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

Posted in |

0 comments:

Post a Comment