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)

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?


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

1 Answers

G.M. Patel On

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