Step1- Open the .edmx file
Step2- Right click in .edmx file and select Update Model from Database
Step3- Select Add tab, select Stored Procedures and select the procedure you want to add and click finish as shown in below figure a
Step4- Build the Entity Project to make sure nothing is broke
Step5- Right click on .edmx file and select Model Browser
Step6- Model Browser Popup will appear as below figure. Click on the Strored Procedures in PricingToolModel.Stroe and click the newly added SP (it will appear here)
Step7- The Add Function Import screen will appear
Based on the return we can set up.
If you are returning a multiple column Click on the Get Column Information First, then click the new Complex Type. After that you can see the Return of Collection will select the Complex and a complex type is generated by EF
If its returning scalar you can select which return type like int, string etc...
If its return entitty (means table) please select the correct table from the list..
Click OK, Then your stored procedure added to EF
Step-8 Access the Stroed Procedure Eg- For a complex model
ReturnModel returnModel = new ReturnModel();
using (Entities context = new Entities())
{
var list = context.spGetMyStoredProcedure(Id).ToList();
returnModel= (from b in list
select new ReturnModel () { Id= Convert.ToInt32(b.Id),
Name = b.Name,
Address=b.Address}
).Distinct().ToList();
}
Step2- Right click in .edmx file and select Update Model from Database
Step4- Build the Entity Project to make sure nothing is broke
Step5- Right click on .edmx file and select Model Browser
Step6- Model Browser Popup will appear as below figure. Click on the Strored Procedures in PricingToolModel.Stroe and click the newly added SP (it will appear here)
Step7- The Add Function Import screen will appear
Based on the return we can set up.
If you are returning a multiple column Click on the Get Column Information First, then click the new Complex Type. After that you can see the Return of Collection will select the Complex and a complex type is generated by EF
If its returning scalar you can select which return type like int, string etc...
If its return entitty (means table) please select the correct table from the list..
Click OK, Then your stored procedure added to EF
Step-8 Access the Stroed Procedure Eg- For a complex model
ReturnModel returnModel = new ReturnModel();
using (Entities context = new Entities())
{
var list = context.spGetMyStoredProcedure(Id).ToList();
returnModel= (from b in list
select new ReturnModel () { Id= Convert.ToInt32(b.Id),
Name = b.Name,
Address=b.Address}
).Distinct().ToList();
}
Comments
Post a Comment