Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Dec 25, 2012 12:31 AM by Decker Dong - MSFT
Dec 24, 2012 12:48 PM|LINK
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.
Dec 24, 2012 12:54 PM|LINK
if you change your database then it usually means that you want to make updates to your application as well. If not then you could go for stored procedures but you'll need to keep the input / output parameters the same as well if you don't want to publish
again as that would mean changing code as well.
You talk about minor changes. Which are those? Changing columns and such? Or laying indexes? If the table and column structures remain the same then you likely could change them without too much hassle, if you start fiddling around with those however then
usually not only that changes and you need to alter code as well.
Dec 24, 2012 01:55 PM|LINK
Thanks for your soon reply.
I don’t want to update my application. Can you provide some sample or article where better explains: “stored procedures need to keep the input / output parameters the same”
Minor changes such as renaming table or column name.
Please also explain these points:
Thnaks in advamce.
Dec 24, 2012 02:07 PM|LINK
as long as you keep your parameters of your stored procedures the same you don't have to alter your code. It's only the inner workings that change. See it as a function in C# where you change the body of the function but not the parameters of the function
so the code that calls the function doesn't need to be changed. This is the same principle.
If you need to change your tables and columns then you didn't specify them well enough up front while developing so basically change the names before going live. If you make use of Code First also start making use of data migrations which got into EF.
Dec 25, 2012 12:31 AM|LINK
Handle database changes and using stored procedure in entity framework?
Maybe I think you can just map your CRUD methods to the generated EF's model tables.
For more, you can refer to this: