iProgrammer
iProgrammer

Reputation: 3107

how to use stored procedures in EntityFramework

how to call stored procedure in EntityFramework?

 DB_9860_agentEntities db = new DB_9860_agentEntities();
 var outputparameter=new ObjectParameter("JobSearchAgentID",typeof(Int32));
 var outputparameter1=new ObjectParameter("ErrorCount",typeof(Int32));
 db.USP_BuildAgentPrifile_Submit_New(110, sess, resumeid, email, keyword, keywordopt, areaid, Convert.ToBoolean(resumesent), Convert.ToBoolean(active), country, zipcode, mile,  outputparameter, outputparameter1);
 ViewData["Jobsearchagentid"] = outputparameter.Value;

where outputparameter and outputparameter1 are output parameters.

Upvotes: 0

Views: 3396

Answers (2)

Shahin
Shahin

Reputation: 12843

This topic provides two examples of how to execute a parameterized stored procedure with the Entity Framework . The first example takes one input parameter and returns a collection of entity objects. The second example takes one input parameter and one output parameter and returns a value in the output parameter. The examples in this topic are based on the School Model. To follow these examples, add the School Model to your project and configure your project to use the Entity Framework . For more information, see How to: Use the Entity Data Model Wizard.

How to: Execute a Query Using a Stored Procedure with In and Out Parameters

Upvotes: 0

Kon
Kon

Reputation: 27431

Once you create your stored procedure, you need to add a function import within EF designer. Follow these steps to do that: http://msdn.microsoft.com/en-us/library/bb896231.aspx

Once that's done, you can call you stored procedure via your entity context instance.

Upvotes: 1

Related Questions