Store procedure in MVC
In this resource you will know how to create store procedure for selecting data in database . Model store procedure is given in this resource .How to Call Store procedure in MVC given in this resource.
Hi
In this Resource you will get code how to create store procedure in sql server 2008 and call the same procedure from MVC project .
personel is table name which contain 5 fields ie ID,Name,Age,DOB,State
The following code is store procedure . The following procedure has a select command which selects the name,Age,DOB,state from the Personel table and returns the value to the code where it calls.
ALTER PROCEDURE dbo.GetStudent
AS
/* SET NOCOUNT ON */
SELECT
Name,
Age,
DOB,
State
FROM dbo.personel
Before creating view create function specification for store procedure in Model browser and create a Sample class name for procedure as GetStudent2_Result
View page for this store procedure find in attachment
controller for returning store procedure result.
public ActionResult Index()
{
StudentDBEntities db = new StudentDBEntities();
public ActionResult Index()
{
var select_student = db.GetStudent2();
return View(select_student);
}
}
Store procedure in MVC
Reference: http://weblogs.asp.net/jalpeshpvadgama/archive/2010/08/18/entity-framework-4-0-bind-stored-procedure-with-result-entity-class.aspx