Thierry
Thierry

Reputation: 6458

Handling multiple resultset from a stored procedure using .SqlQuery with Entity Framework

I'm trying to return 2 results from a stored procedure i.e. PageCount and list of rows.

I created the an object:

public class MyData
{
    public int PageCount {get;set;}
    public ICollection<MyRowObject> Items {get;set;}
}

and I'm calling the following EF code:

var result = this.Database.SqlQuery<T>('EXEC MySP @param1', parameters)
                          .FirstOrDefault();

But when I run it, it only returns the PageCount and the Items collection which contains the rows is set to null.

The SP is definitely working when executed in SQL as it is returning the PageCount and the list of matching rows.

Any ideas why this is not working on how I can fix this?

Thanks

Please note that I have found various questions on StackOverflow but they are all using a reader and I'm just curious as to whether or not it can be achieved using .SqlQuery.

Update 1:

I don't know if this is achievable but here's a link I thought I'd share as it's a nicely written article but once again, it's using the Reader.

Entity Framework 6 Multiple Result Sets with Stored Procedures

Upvotes: 1

Views: 1291

Answers (1)

G.M. Patel
G.M. Patel

Reputation: 51

For Return Multiple ResultSet using Entity Framework from Stored Procedure, Please see the below link. I think it's useful for you.

https://www.codeproject.com/Tips/1072284/Return-Multiple-Result-Set-using-Entity-Framework

Upvotes: 1

Related Questions