I am new to EF4 .
I am using a stored procedure that returns 2 resultsets? I understand that this is not possible and not supported.Pity!
What is the workaround? any code examples?
Thanks a lot
In order to get multiple result sets working we need to drop to the ObjectContext API by using the IObjectContextAdapter interface. Once we have an ObjectContext then we can use the Translate method to translate the results of our stored procedure into entities that can be tracked and used in EF as normal.
Most stored procedures return multiple result sets. Such a stored procedure usually includes one or more select statements. The consumer needs to consider this inclusion to handle all the result sets.
In order to fetch the multiple returned values from the Stored Procedure, you need to make use of a variable with data type and size same as the Output parameter and pass it as Output parameter using OUTPUT keyword. You can also make use of the Split function to split the comma separated (delimited) values into rows.
A blog post on the subject: http://blogs.infosupport.com/blogs/willemm/archive/2010/07/16/ado-net-entity-framework-advanced-scenarios-working-with-stored-procedures-that-return-multiple-resultsets.aspx
Some possibly useful extensions: http://code.msdn.microsoft.com/EFExtensions
EF5 now supports this:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With