在asp.net Web表单应用程序中使用Entity Framework时,使用存储过程进行CRUD操作是否合适? [英] Is it good to use stored procedure for CRUD operation while using Entity Framework in asp.net web form application?

查看:87
本文介绍了在asp.net Web表单应用程序中使用Entity Framework时,使用存储过程进行CRUD操作是否合适?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好!!!



我正在实施一个项目,我将实体框架用作数据访问层。

我有实现了几个存储过程,用于在Sql Server中对数据库进行CRUD操作;现在我想使用Entity Framework的那些存储过程从我的应用程序执行CRUD操作,那么使用存储过程和实体框架是否合适?如果我使用存储过程与实体框架有什么好处吗?



谢谢!!!!!

解决方案

如果你愿意,你可以使用SP,但是你几乎要打败了完全使用Entity Framework的对象。您将获得的唯一真正优势是,从SP创建数据实体框架将为您提供已填充数据的特定类,而不是像使用ADO.net那样从SP读取原始数据。


实体框架最终是一个ORM,它可以帮助那些不知道如何编写好的SQL查询的开发人员,但显然该工具在性能方面需要付出一些代价。



存储过程是预编译的,而EF每次都会生成查询。

此外,基于SP的应用程序更易于维护,即假设您已在生产服务器上部署项目现在你意识到你要改变一些计算或数据检索逻辑,你可以简单地连接到实时数据库并更改相应的存储过程,但在其他情况下(完全使用EF和LINQ)你必须在应用程序中进行更改代码,然后重新部署代码!



因此,如果您擅长编写查询,请继续执行存储过程。 :)

Hello there!!!

I am implementing a project where I am using Entity Framework as Data Access Layer.
I have implemented several stored procedures for doing CRUD operations on database in Sql Server; Now I want to use those stored procedures with Entity Framework for doing CRUD operations from my application, So is it good to use Stored Procedures with Entity Framework and Is there any benefit if I am using Stored Procedures with Entity Framework?

Thanks!!!!!

解决方案

You can use SPs if you want, but you're pretty much defeating the object of using Entity Framework at all. The only real advantage you'll gain is when creating data from the SPs Entity Framework will give you specific classes back with the data already populated rather than you having to read the raw data from an SP like you would with ADO.net.


Entity framework is ultimately an ORM which facilitates the developer who doesn't know how to write good SQL queries but obviously that facility comes at some cost in terms of performance.

Stored procedures are pre-compiled while EF will generate query every time.
Furthermore the SP based application is more maintainable i.e. suppose you've deployed the project at production server and now you realize that you've to change some computation or data retrieval logic, you can simply connect to live db and change respective stored procedures but in other case (using EF & LINQ entirely) you'll have to make changes in your application code and then re-deploy the code!

So if you are good at writing queries then go ahead with stored procedures. :)


这篇关于在asp.net Web表单应用程序中使用Entity Framework时,使用存储过程进行CRUD操作是否合适?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆