How To Implement Stored Procedure in Entity Framework Database

If you want to know how to implement stored procedure in entity framework database, then, Here are the steps to implement the same.

We can also access stored procedures in a .net application like tables. These procedures are converted as c# methods.
At the time of adding stored procedures, Entity framework generates following items:

1. C# method: method name same as stored procedure name.
2. Result class: Name of the class is prepared as follows:
Syntax: Procedurename_results
Eg: getemployees_results

Steps to Implement

1. Create required stored procedure in the database.
2. Add stored procedure in a .net application using entity framework.
3. Invoke the stored procedure using c# methods with help of data context class object.

Eg: Create MVC application to display employee details by invoking a stored procedure from entity framework.

1. Create required stored procedure on SQL server

Create procedure <g class="gr_ gr_42 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" id="42" data-gr-id="42">getemps</g>
@dno int
Select * from emp where deptno=@dno

2.Create MVC Application (webapplication1)and add above-stored procedure by using Entity Framework.
3.Build the project.

 Using webapplication1.Models;
Namespace webapplication1.controllers
 Public class Homecontroller: Controller
Empdbentities db=new Empdbentities ();
Public ActionResult Index()
List<Getemps_Result> emplist=db.Getemps(10).tolist();
return view(emplist);


@using Webapplication1.Models;
@model Ienumberable<Getemps_result>

<h1>Employee Details</h1>
<table border=”2” width=”400”>
Foreach(GetEmps_result item in Model)