I'm using EF in my MVC project. In my project I need to use stored procedures. My problem is to use output parameter with stored procedures. I have no idea how to do that
When you create your entity model, you should make sure that you include stored procedures. Then, create Function Imports for them:
That's it. Now you can use that in code.
using (MyEntities myContext = new MyEntities ())
{
System.Data.Objects.ObjectParameter output = new System.Data.Objects.ObjectParameter("OutputParameterName", typeof(int));
myContext.GetCustomerCount(output);
Console.WriteLine(output.Value);
}
Modified Answer for Entity Framework 6.x / VS 2015 - notice the namespace change:
using (MyEntities myContext = new MyEntities ())
{
System.Data.Entity.Core.Objects.ObjectParameter output = new System.Data.Entity.Core.Objects.ObjectParameter("OutputParameterName", typeof(int));
myContext.GetCustomerCount(output);
Console.WriteLine(output.Value);
}