简体   繁体   English

如果我的所有sql server数据库访问都是通过存储过程完成的

[英]If all my sql server database access is done thru stored procedures

If all my sql server database access is done thru stored procedures, and I plan on continuing that practice, is using linq2sql and/or the entity framework for future projects an unnecessary layer of complexity that doesn't add much value? 如果我的所有sql server数据库访问都是通过存储过程完成的,并且我计划继续这种做法,那么使用linq2sql和/或实体框架为未来的项目提供一个不必要的复杂层,它不会增加太多价值?

Related question: is Microsoft trying to steer developers away from relying on stored procs for data access? 相关问题:微软是否试图引导开发人员远离依赖存储过程来进行数据访问?

No. LINQ2SQL adds a lot of value in terms of being able to easily map your database entities to classes in your code and work with those classes easily with native langugage constructs. LINQ2SQL在能够轻松地将数据库实体映射到代码中的类并使用本机语言结构轻松处理这些类方面增加了很多价值。 You can easily map the CRUD operations of the generated entity class onto your stored procedures if you want. 如果需要,可以轻松地将生成的实体类的CRUD操作映射到存储过程。 I do find that some things no longer require stored procedures to work easily and so I have moved away from using them, but you are not forced to. 我发现有些东西不再需要存储过程来轻松工作,所以我已经不再使用它们了,但是你不会被迫。 Essentially what LINQ2SQL can do is replace much, if not all, of your DAL, saving you from having to write this code. 基本上LINQ2SQL可以做的就是替换你的DAL(如果不是全部的话)很多,这样你就不必编写这段代码了。

I use Linq2sql for calling my stored procedures as well just because its so fast to generate .net code I can call from my app, its just drag and drop, basically done in seconds. 我使用Linq2sql来调用我的存储过程也是因为它生成.net代码的速度非常快,我可以从我的应用程序中调用,它只需拖放,基本上只需几秒钟即可完成。 Still I think you need to ask yourself how much time you spend maintaing those stored procedures. 我仍然认为你需要问问自己维护这些存储过程花了多少时间。 If you do you would save a lot of time using linq2sql doing your crud calls. 如果你这样做,你会节省很多时间使用linq2sql做你的crud调用。 I use sprocs only when doing multiple step operations on the database. 我只在数据库上执行多步操作时才使用sprocs。

LINQ-to-SQL supports mapping lots of operations (including CRUD) to stored procedures, but you lose composability - ie you can't just add (exp).Where(x=>x.IsActive) . LINQ-to-SQL支持将大量操作(包括CRUD)映射到存储过程,但是你失去了可组合性 - 即你不能只添加(exp).Where(x=>x.IsActive) One option there is table-valued functions (UDFs) in place of stored procedures that query data; 一种选择是表值函数(UDF)代替查询数据的存储过程; this also presents a more rigid meta model (rather than SET FMT_ONLY ON , which is hit'n'miss). 这也提出了一个更严格的元模型(而不是SET FMT_ONLY ON ,这是hit'n'miss)。

That way, your query methods are composable at the database; 这样,您的查询方法可以在数据库中组合; but note that Entity Framework does not support this, even though LINQ-to-SQL does. 但请注意,即使LINQ-to-SQL确实存在,Entity Framework 也不支持此功能。

Just to address your related question: The benefits of using stored procedures are not as prominent as they once were. 只是为了解决您的相关问题:使用存储过程的好处并不像以前那么突出。 Though I would not go as far as saying stored procedures are evil, as some have said in the past ( http://www.tonymarston.net/php-mysql/stored-procedures-are-evil.html - this is a very nice article though), I would say that the use of dynamic sql, as long as it's done in a well defined structured way, is perfectly acceptable these days. 虽然我不会说存储过程是邪恶的,正如一些人在过去所说的那样( http://www.tonymarston.net/php-mysql/stored-procedures-are-evil.html-这是一个非常虽然好文章,但我会说,动态sql的使用,只要它以一种定义良好的结构化方式完成,这些天是完全可以接受的。

I don't this Microsoft are trying to steer developers away from using stored procs but that dynamic sql should be seen as an acceptable option. 我不是微软试图引导开发人员使用存储过程,但动态sql应被视为可接受的选择。

你失去了编写Linq查询的能力,这是linq-to-sql的最佳部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SQL Server中的所有存储过程都存储在哪个数据库中? - All the stored procedures in SQL Server are stored in which database? 为什么SQL Server sys.objects不包含数据库中的所有存储过程等? - Why doesn't SQL Server sys.objects contain all the stored procedures, etc in my database? SQL Server:如何从数据库中的所有存储过程中找到特定值? - SQL Server : how can I find the specific value from all stored procedures in my database? C#访问SQL Server数据库存储过程和视图 - C# access to SQL Server database stored procedures and views 如何在SQL Server数据库中一次删除所有存储过程? - How to drop all stored procedures at once in SQL Server database? 所有 SQL 服务器数据库存储过程的屏幕转储 - Screen dump of all SQL Server database stored procedures 如何统计SQL服务器中一个数据库的所有存储过程? - How to count all stored procedures in the SQL Server for a database? 如何在SQL Server中查找使用“我的数据库”的存储过程 - How to find stored procedures which are using 'My Database' in SQL Server SQL Server-保护我的存储过程 - SQL Server - Protect my stored procedures SQL Server 2012:如何将所有数据库存储过程编写为单独的.sql文件? - SQL Server 2012 : How to script all database stored procedures into separate .sql files?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM