Quantcast
Channel: amitpatelit » MVC
Viewing all articles
Browse latest Browse all 11

Execute Store procedure in Entity framework

$
0
0

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.

public List<Menu> GetMyData(long intUserID)
{
List<Role> oMenuList = new List< Role >();
Business.Model. Role oRole = new Role ();
oMenu.MenuId = 1;
List<Role> oMenuDataList = this.Database.SqlQuery<Menu>("exec GetRoleData {0}", intUserID).ToList<Role>();
}

In Above code List<Role> Role is model so that is fill by storeprocedure “GetRoleData”.

Let me mail:amitpatel.it@gmail.com for any questions.

Thanks

Amit Patel

“Enjoy Programming”



Viewing all articles
Browse latest Browse all 11

Trending Articles