Is it possible to return 2 selects with 1 Iqueryable?
I have a method that basically returns some records but I use it for paging so I also need to return the number of TOTAL records. It’s working, but rather than creating a concrete class with 2 properties (1 for the count and 1 for my select) I would rather stick with IQueryable but I am unsure if it is going to work.
Here’s an example what is returned from my COUNT:
56
This refers to the amount records in the table.
And then my select returns a page with a number of records per page i.e.
ID Name
32 John
33 Peter
34 David
so as you can see I have in effect 2 selects – 1 that returns the amount of records in the table and 1 that returns a subset of records from the table. Of course I am executing these 2 values as 2 separate queries in my method (C#) so I have 2 iqueryable vars in effect and I need to return both from the method.
So I wanted to keep my return method in line with the standard for a repository pattern i.e. returning IQueryable – but how would I do this?
I didn’t want to create 2 methods, 1 for returning the count and the other for returning the subset and as I say I didn’t want to change the return type to a concrete class (for example) that has 2 properties called Count and Data.
No, basically. LINQ-to-SQL itself supports multiple grids, but typically when calling a stored-proc, and not via
IQueryable<T>. And since you don’t want to change the schema you can’t use a cheekyExecuteQuery<T>with a dummy column. So no.You could, however, do something like the following (which will of course mandate 2 round-trips to the server):