处理数据库更改并在实体框架中使用存储过程? [英] Handle database changes and using stored procedure in entity framework?

查看:63
本文介绍了处理数据库更改并在实体框架中使用存储过程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Quote:

我在使用DbContext的asp.net mvc 4应用程序中使用Code first模型。目前,我使用DbContext类的简单添加,更新和删除以及查找方法。

但我想使用存储过程来添加,更新,删除和查找数据,以便每当我们对数据库进行一些小的更改时。我不想在数据库中发生一些小的更改时重新编译并发布整个应用程序。假设我们添加一些列或重命名列和表名,我们还需要对模型结构进行更改。

你能告诉我更好的方法来处理它以及如何实现这个目标吗?使用存储过程与实体框架代码第一模型是更好的方法吗?

如果我们使用数据库第一模型,我们需要从数据库更新模型和重新编译并发布它?

请尽快回复。

谢谢。

I am using Code first model in my asp.net mvc 4 application with DbContext. Currently, I am using simple Add, Update and Delete and Find methods of DbContext class.
But I want to use stored procedures to add, update, delete and find the data so that whenever we do some minor changes in the database. I don’t want to recompile and publish the whole application whenever some minor changes occur in the database. Suppose we add some column or rename the column and table name, we also need to do changes in the model structure.
Can you tell me the better way to handle it and how to achieve this?
Is using stored procedure with Entity framework code first model is a better way?
If we are using database first model, the same problem arising that we need update the model from database and recompile and publish it?
Please reply ASAP.
Thanks.

推荐答案

所有阅读的内容都会快速浏览一下这篇文章:

EF CF中的SP
Hi , firts of all read take a quick look at this article :
SP in EF CF


虽然你可以使用EF存储过程,但是那么使用创建的模型的目的是什么,以保持它将弥合关系之间的差距l模型和面向对象的编程?但是,在绘制了体系结构后,很少更改数据库的数据类型和列。在您的情况下,如果您经常更改数据库的体系结构,请不要使用EF。去寻找ADO.Net。但是,数据库体系结构的更改将使您更新业务层和数据库层。所以,无论哪种方式,你都必须进行调整。
Although you can use stored procedures with EF, but then what is the objective of using a model that was created keeping in view that it will bridge the gap between relational model and object oriented programming? However it is rare that you change datatypes and columns of the database after the architecture has already been drawn. In your case if you frequently change the architecture of your database, do not use EF. Go for ADO.Net. Still, a change in the architecture of database will make you update your business layer, and database layer. So, either way you have to make adjustment.


这篇关于处理数据库更改并在实体框架中使用存储过程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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