0

大家好 我们知道 SqlCommand 对象的 CommandType 属性有 3 个选项:TableDirect、Text 和 StoredProcedure 或“SP”。

知道“SP”比其他两个选项有好处,我的问题是您是否在自己的系统中制作了很多 SP?

或者您有什么解决方案而不是创建 SP?

谢谢

4

4 回答 4

1

除了创建存储过程,您还可以使用对象关系映射

如:

linq to sql
Nhibernate
Entity Framework

数据访问:SP 与 ORM

选择最适合您的方式。

于 2011-01-27T06:38:51.120 回答
1

Re: your first question When you go down the path of stored procedures, the number of stored procedures begins to grow continually for the life of the project. Outside of the basic CRUD operations, each stored procedure tends to be tightly bound to a particular problem and not very re-usable. A rule of thumb is that I can expect 8-12 stored procedures for each data table (excluding reference or code tables, such as the list of states or countries).

The very large number of procs makes naming conventions very important so that you can find anything without constantly visually re-scanning the whole list of 400-500 procs.

Re: your second question There are a lot of ugly things that happen with sql written inside of strings inside of C# or VB.NET -- it's error prone, ugly, etc.

Linq, nHybernate and many others exist, but the "concept count" (the number of things you need to learn to start being productive), is much higher than learning how to write a good stored procedure executer in C#.

于 2011-01-28T20:28:22.780 回答
1

在所有生产系统中,我使用 SP 和纯 ADO.NET Core 来访问数据。系统有 100-300 个表和大约 500-1000 个存储过程。

大多数数据访问代码是使用工具生成的。如果您有兴趣使用/修改它,我已经在我的博客上发布了源代码和示例应用程序。该工具可以在大约 20-25 秒内生成超过 100,000 行代码,以针对具有大约 750 个存储过程的数据库。

数据访问层 - 代码生成

当然,如果您不熟悉数据库、数据建模/设计和存储过程,您可能最好使用 Linq to SQL 或 EF4(实体框架版本 4)或类似工具。如果您需要蛮力性能,那么 ADO.NET 核心和存储过程是您的最佳选择。

于 2011-01-27T06:23:56.093 回答
0

我尝试确保仅为数据库功能而不是业务逻辑创建存储过程。

当我有一些有点模糊的数据库架构并且我想对调用者隐藏它时,它就是数据库功能。

当它只是我的应用程序添加或更新的方式或它们进行多少验证等时,它就是业务逻辑。

于 2011-02-25T02:43:44.273 回答