Value of the output parameter

entity-framework

Question

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

1
23
11/21/2018 4:35:47 PM

Accepted Answer

When you create your entity model, you should make sure that you include stored procedures. Then, create Function Imports for them:

  1. Open your Entity Model in Visual Studio
  2. The Model Browser should open on the right side of the screen
  3. In the Model Browser, you need to select the stored procedure and click Add Function Import to create the function for the stored procedure.
  4. A dialog box will open to select the stored procedure and return type

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);            
}
39
11/8/2012 3:05:49 PM

Popular Answer

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);            
}


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow