Md Mominul Islam | Software and Data Enginnering | SQL Server, .NET, Power BI, Azure Blog

while(!(succeed=try()));

LinkedIn Portfolio Banner

Latest

Home Top Ad

Responsive Ads Here

Post Top Ad

Responsive Ads Here

Sunday, January 13, 2013

Execute Store procedure in Entity framework

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”.

No comments:

Post a Comment

Thanks for your valuable comment...........
Md. Mominul Islam

Post Bottom Ad

Responsive Ads Here