Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework stored procedure with multiple resultsets?

Tags:

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

like image 446
user9969 Avatar asked Nov 03 '10 11:11

user9969


People also ask

How can we get multiple result sets from a stored procedure using Entity Framework?

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.

Can a stored procedure return multiple result sets?

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.

How can I return multiple values from a stored procedure in SQL Server?

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.


2 Answers

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

like image 29
Kalle Avatar answered Oct 23 '22 02:10

Kalle


EF5 now supports this:

  • EF Releases
  • Stored Procedures with Multiple Result Sets
like image 86
Christo Avatar answered Oct 23 '22 01:10

Christo