Last post Dec 19, 2014 12:46 AM by Fei Han - MSFT
Dec 18, 2014 09:03 AM|paul.lonsdale|LINK
I have a rather complex stored procedure (written by someone else I may add!) that has a parameter called @mode and dependant on the value of that parameter it will return a recordset containing different columns. So for example:
When @mode = 1 it returns:
SELECT BlahID, BlahName, BlahOtherData FROM HereAndThere WHERE ... etc.
...and when @mode = 2 it returns:
SELECT BlahID, BlahDifferentColumn, BlahYetMoreData FROM SomewhereElse
I can't really change the database for this project so I am using Entity Framework in a "Database First" way and when I add the above SP it rightly creates me a nice function in my DBContext class with all of the correct parameters but the object it creates
for the result only contains the columns for the first SQL statement above. It doesn't seem to recognise that the SP may return different columns under certain circumstances.
My question is, how can I use EF for this kind of SP?
Dec 19, 2014 12:46 AM|Fei Han - MSFT|LINK
Thanks for your post.
Firstly, I recommend to execute the stored procedure in SQL server to make sure whether stored procedure works fine or not under different circumstances.
Secondly, those articles are about “Stored Procedure in Entity Framework”, you could refer to it.
Hope it will be helpful to you.