Lets Have a fun with Technology.

BTemplates.com

Follow by Email

Wednesday, January 27, 2016

Call Stored Procedure from Entity Framework



First Create an edmx file.

Double click your edmx file and right click your model,Choose Function Import In the pop-up dialog,

Choose the SP that you want to import as a function.

Now you can use it through the database Context like below.



using (EntityContext ec = new EntityContext())

{

    ec.StoredProcdure here(Parameters);

}


You can also refer below articles for same.

For Database First / Model First you can set up EF to call the SPs automatically:

http://www.asp.net/web-forms/tutorials/getting-started-with-ef/the-entity-framework-and-aspnet-getting-started-part-7

For Code First you have to call them manually:

http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/advanced-entity-framework-scenarios-for-an-mvc-web-application

0 comments:

Post a Comment