Call Store Procedure using Entity Framework in C#.Net

Posted by Naraayanan under ADO.NET on 8/2/2013 | Points: 10 | Views : 11974 | Status : [Member] | Replies : 3
Hi All,
How to call Store procedure using Entity Framework in C#.net ? what is the use of Function Import in Entity framework in VS 2008?

Regards,
Lakshmi Naraayanan.S
http://dotnettechrocks.blogspot.in/
http://abaprocker.blogspot.com/



Responses

Posted by: aswinialuri-19361 on: 8/2/2013 [Member] Starter | Points: 25

Up
0
Down
hi,
refer this link it might be helpful to you
http://forums.asp.net/t/1787152.aspx/1
http://www.c-sharpcorner.com/UploadFile/ff2f08/call-store-procedure-from-entity-framework/

Mark as Answer if it helps you
Thanks&Regards
Aswini Aluri

Naraayanan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 8/5/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down

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

Additional references:
http://www.cshandler.com/2011/04/calling-stored-procedure-using-adonet.html
http://stackoverflow.com/questions/2406331/calling-entity-framework-function-import-from-code

The function import gives you several options. It lets you name the resulting function that will appear on the DbContext. It also lets you choose what the stored procedure should return. You can map the return value to a scalar, an existing entity in the model, or to a new or existing complex type.
http://rationalgeek.com/blog/function-imports/

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Naraayanan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 8/6/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Process is as follows to call a stored procedure:
1) Import the stored procedure by using "Add Function Imports" option ( ex: Imported function name of the Stored Procedure is GetCountByLastName
2) GetCountByLastName(InputParam, outputCountParam) has to be called as follows:

var outputParam = new ObjectParameter("lastNameCount", new Int32());
var results = context.GetCountByLastName("Adams", outputParam);

Refer http://msdn.microsoft.com/en-us/data/gg699321.aspx

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Naraayanan, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response