Sunday, January 13, 2013
0 comments

Execute Store procedure in Entity framework

11:06 AM
In MVC application generally we are using entity frame work (dbcontext) to manage and retrieve database related operation, but in some case suppose we have few complex logic for that need to write store procedure so below are the code for retrieve data from store procedure in MVC Mode by entity frame work.
In this class I have inherited by “DBContext” class so “Database” is part of data context.
1public List<Menu> GetMyData(long intUserID)
2{
3List<Role> oMenuList = new List< Role >();
4Business.Model. Role oRole = new Role ();
5oMenu.MenuId = 1;
6List<Role> oMenuDataList = this.Database.SqlQuery<Menu>("exec GetRoleData {0}", intUserID).ToList<Role>();
7}
In Above code List<Role> Role is model so that is fill by storeprocedure “GetRoleData”.

0 comments:

 
Toggle Footer