Came across this:
碰到了这个:
http://www.eggheadcafe.com/articles/adonet_source_code_generator.asp
And wondering if this is the right solution as I am not that big of a fan of creating a class for every stored procedure or do I use Enterprise Library for ASP.net 2.0 project.
并且想知道这是否是正确的解决方案,因为我不是为每个存储过程创建类的粉丝,或者我使用Enterprise Library for ASP.net 2.0项目。
4 个解决方案
#1
6
You definitely shouldn't be creating a class for every stored procedure. There are a number of approaches you can take to handling your database interactions. You should have a good look at the major frameworks out there and decide which one best suits you. The Castle Project solution is great, and relies on nHibernate (nHibernate). LINQ is a similar offering by Mircrosoft (LINQ Project). Both of these solutions are full ORM frameworks (Object Relational Mapping) and will generate dynamic SQL to persist your objects in the database. Each also has it's own quirks and likes you to structure your objects in particular ways. If you don't want to manage the SQL your system uses, I would definitely recommend one of these approaches.
你绝对不应该为每个存储过程创建一个类。您可以采用多种方法来处理数据库交互。你应该好好看看那里的主要框架,并决定哪一个最适合你。 Castle Project解决方案非常棒,并且依赖于nHibernate(nHibernate)。 LINQ是Mircrosoft(LINQ项目)提供的类似产品。这两个解决方案都是完整的ORM框架(对象关系映射),并将生成动态SQL以将对象保存在数据库中。每个人都有它自己的怪癖,并喜欢你以特定的方式构建你的对象。如果您不想管理系统使用的SQL,我肯定会推荐其中一种方法。
I come from a database background, and prefer a bit more control over my SQL. In particular I like to have my interractions handled by stored procedures. I find this enables me to control both the SQL better for optimisation, but helps me manage database security in a more friendly manner. To accommodate this approach, I recommend something like iBatis (iBatis). iBatis isn't a full ORM, but rather a simple SQL mapper. The downside to my approach is that you need to write a lot more code (SQL), but I don't mind the trade-off.
我来自数据库背景,并且更喜欢对我的SQL进行更多控制。特别是我喜欢通过存储过程处理我的交互。我发现这使我能够更好地控制SQL以进行优化,但帮助我以更友好的方式管理数据库安全性。为了适应这种方法,我推荐像iBatis(iBatis)这样的东西。 iBatis不是一个完整的ORM,而是一个简单的SQL映射器。我的方法的缺点是你需要编写更多的代码(SQL),但我不介意权衡。
#2
0
Is there any possibility of upgrading to framework 3.5? if so take a look at LINQ to SQL and Entity Framework as this will accomplish alot of this for you.
是否有可能升级到框架3.5?如果是这样,请看一下LINQ to SQL和Entity Framework,因为这将为您完成很多这样的事情。
If not then as long as it generates standard code that doesnt tie you into 3rd party libraries then you could certainly use it. At my workplace we have our own generator similar to this and it works well although we will shortly be moving to LINQ to SQL.
如果没有,那么只要它生成标准代码并不会将您绑定到第三方库,那么您当然可以使用它。在我的工作场所,我们有自己的类似于此的生成器,虽然我们很快将转向LINQ to SQL,但它运行良好。
#3
0
There are many ways of wrapping a database table in a C# class; you probably want to investigate a few alternatives before choosing between the one you've linked to and the Entity Framework.
在C#类中包装数据库表的方法有很多种;在选择链接到的实体框架和实体框架之前,您可能想要研究一些替代方案。
There's a software pattern called the "active record pattern" which describes exactly this approach - one C# class for each table, with load/save methods like Customer.GetById(), Customer.Save(), and so on.
有一种称为“活动记录模式”的软件模式,它描述了这种方法 - 每个表一个C#类,使用加载/保存方法,如Customer.GetById(),Customer.Save()等。
For ASP.NET 2.0, check out the Castle Project's ActiveRecord implementation and a third-party Visual Studio plugin tool called ActiveWriter that lets you generate class wrappers for your tables using a drag'n'drop interface.
对于ASP.NET 2.0,请查看Castle Project的ActiveRecord实现和名为ActiveWriter的第三方Visual Studio插件工具,该工具允许您使用拖放界面为表生成类包装器。
#4
0
You will need to determine at what point you need sets of data that are composed from your tables, and whether you want SQL to produce these with stored procedures or if your business logic layer will handle these. As Dr8k says, nHibernate will create SQL for you, but there is a learning curve with nHibernate. The ORM will be in control of how you are getting the data and depending on your environment and DBA's conmfort level you may other issues to overcome.
您需要确定在什么时候需要从表中组成的数据集,以及是否希望SQL使用存储过程生成这些数据,或者您的业务逻辑层是否将处理这些数据。正如Dr8k所说,nHibernate会为你创建SQL,但是nHibernate有一个学习曲线。 ORM将控制您获取数据的方式,并根据您的环境和DBA的要求,您可能需要克服其他问题。
If you more comfortable with SQL, then there is another tool called SubSonic that will create wrappers ala Active Record for you while offering you the ability to use stored procedures as well. There is also a nice query tool with a fluent interface that you can use if you are not able to use LINQ.
如果您对SQL更熟悉,那么还有另一个名为SubSonic的工具,它将为您创建包装器ala Active Record,同时为您提供使用存储过程的能力。还有一个很好的查询工具,如果你不能使用LINQ,你可以使用流畅的界面。
#1
6
You definitely shouldn't be creating a class for every stored procedure. There are a number of approaches you can take to handling your database interactions. You should have a good look at the major frameworks out there and decide which one best suits you. The Castle Project solution is great, and relies on nHibernate (nHibernate). LINQ is a similar offering by Mircrosoft (LINQ Project). Both of these solutions are full ORM frameworks (Object Relational Mapping) and will generate dynamic SQL to persist your objects in the database. Each also has it's own quirks and likes you to structure your objects in particular ways. If you don't want to manage the SQL your system uses, I would definitely recommend one of these approaches.
你绝对不应该为每个存储过程创建一个类。您可以采用多种方法来处理数据库交互。你应该好好看看那里的主要框架,并决定哪一个最适合你。 Castle Project解决方案非常棒,并且依赖于nHibernate(nHibernate)。 LINQ是Mircrosoft(LINQ项目)提供的类似产品。这两个解决方案都是完整的ORM框架(对象关系映射),并将生成动态SQL以将对象保存在数据库中。每个人都有它自己的怪癖,并喜欢你以特定的方式构建你的对象。如果您不想管理系统使用的SQL,我肯定会推荐其中一种方法。
I come from a database background, and prefer a bit more control over my SQL. In particular I like to have my interractions handled by stored procedures. I find this enables me to control both the SQL better for optimisation, but helps me manage database security in a more friendly manner. To accommodate this approach, I recommend something like iBatis (iBatis). iBatis isn't a full ORM, but rather a simple SQL mapper. The downside to my approach is that you need to write a lot more code (SQL), but I don't mind the trade-off.
我来自数据库背景,并且更喜欢对我的SQL进行更多控制。特别是我喜欢通过存储过程处理我的交互。我发现这使我能够更好地控制SQL以进行优化,但帮助我以更友好的方式管理数据库安全性。为了适应这种方法,我推荐像iBatis(iBatis)这样的东西。 iBatis不是一个完整的ORM,而是一个简单的SQL映射器。我的方法的缺点是你需要编写更多的代码(SQL),但我不介意权衡。
#2
0
Is there any possibility of upgrading to framework 3.5? if so take a look at LINQ to SQL and Entity Framework as this will accomplish alot of this for you.
是否有可能升级到框架3.5?如果是这样,请看一下LINQ to SQL和Entity Framework,因为这将为您完成很多这样的事情。
If not then as long as it generates standard code that doesnt tie you into 3rd party libraries then you could certainly use it. At my workplace we have our own generator similar to this and it works well although we will shortly be moving to LINQ to SQL.
如果没有,那么只要它生成标准代码并不会将您绑定到第三方库,那么您当然可以使用它。在我的工作场所,我们有自己的类似于此的生成器,虽然我们很快将转向LINQ to SQL,但它运行良好。
#3
0
There are many ways of wrapping a database table in a C# class; you probably want to investigate a few alternatives before choosing between the one you've linked to and the Entity Framework.
在C#类中包装数据库表的方法有很多种;在选择链接到的实体框架和实体框架之前,您可能想要研究一些替代方案。
There's a software pattern called the "active record pattern" which describes exactly this approach - one C# class for each table, with load/save methods like Customer.GetById(), Customer.Save(), and so on.
有一种称为“活动记录模式”的软件模式,它描述了这种方法 - 每个表一个C#类,使用加载/保存方法,如Customer.GetById(),Customer.Save()等。
For ASP.NET 2.0, check out the Castle Project's ActiveRecord implementation and a third-party Visual Studio plugin tool called ActiveWriter that lets you generate class wrappers for your tables using a drag'n'drop interface.
对于ASP.NET 2.0,请查看Castle Project的ActiveRecord实现和名为ActiveWriter的第三方Visual Studio插件工具,该工具允许您使用拖放界面为表生成类包装器。
#4
0
You will need to determine at what point you need sets of data that are composed from your tables, and whether you want SQL to produce these with stored procedures or if your business logic layer will handle these. As Dr8k says, nHibernate will create SQL for you, but there is a learning curve with nHibernate. The ORM will be in control of how you are getting the data and depending on your environment and DBA's conmfort level you may other issues to overcome.
您需要确定在什么时候需要从表中组成的数据集,以及是否希望SQL使用存储过程生成这些数据,或者您的业务逻辑层是否将处理这些数据。正如Dr8k所说,nHibernate会为你创建SQL,但是nHibernate有一个学习曲线。 ORM将控制您获取数据的方式,并根据您的环境和DBA的要求,您可能需要克服其他问题。
If you more comfortable with SQL, then there is another tool called SubSonic that will create wrappers ala Active Record for you while offering you the ability to use stored procedures as well. There is also a nice query tool with a fluent interface that you can use if you are not able to use LINQ.
如果您对SQL更熟悉,那么还有另一个名为SubSonic的工具,它将为您创建包装器ala Active Record,同时为您提供使用存储过程的能力。还有一个很好的查询工具,如果你不能使用LINQ,你可以使用流畅的界面。