There is a stored procedure that executes exec
command and returns some columns. Columns and number of them are varied. How can I call this stored procedure from Entity Framework?
Asked
Active
Viewed 8,214 times
2
-
5This is a **horribly bad** design - and EF doesn't support it (and that's a good thing!). Your stored procedure should be **stable** and return one "shape" of data only - these "do it all" procedures are just really really ugly to use and to maintain - I'd strongly recommend **against** this practice! – marc_s Feb 19 '14 at 06:14
-
6Well I basically agree, but whether a design is good or bad is always subjective, e.g. DOES depend on the context. – Bart Nov 03 '14 at 09:23
-
@Bart: I totally agree with you. we can not say it a bad design, although it might be a functional requirement. – Jitendra Pancholi Mar 29 '17 at 11:23
1 Answers
-1
You have to create a ComplexType in the EntityFramework and then call the stored procedure:
public ObjectResult<yourComplextype> MyMethod()
{
return _dbContext.usp_Yourprocedure();
}

Bhupendra Shukla
- 3,814
- 6
- 39
- 62
-
2Sure - but if the "shape" of the data changes with each call - what is this complex type going to be?? – marc_s Feb 19 '14 at 06:14
-
-
@marc_s I think we can also call the sp without using ComplexType – Bhupendra Shukla Feb 19 '14 at 06:17