MVC Grid / Pager & Stored Procedure result set

138 views
Skip to first unread message

doucol

unread,
Oct 30, 2009, 12:30:34 PM10/30/09
to mvccontrib-discuss
Hi,

I'm trying to get the grid an pager to work with a result set returned
by a stored procedure and I'm getting an exception when the
"Html.Pager" is called. The exception is "The result of a query
cannot be enumerated more than once."

I have the stored procedure imported into the entity framework and
it's mapping returns an "IEnumerable<WorkOrderClaim>" where
WorkOrderClaim is an entity type.

Is what I'm trying to do even possible?

thanks much
-doug

Jeremy Skinner

unread,
Oct 30, 2009, 12:55:05 PM10/30/09
to mvccontri...@googlegroups.com
How're you generating the IPagination instance?

Jeremy


2009/10/30 doucol <doug.c...@gmail.com>

doucol

unread,
Oct 30, 2009, 3:04:22 PM10/30/09
to mvccontrib-discuss
Hi Jeremy,

The IPagination instance is being generated like this:

IEnumerable<WorkOrderClaim> ret = _db.WorkOrderClaims(startDate,
endDate);
return View(ret.AsPagination(page.GetValueOrDefault(1), 20));

Where "_db.WorkOrderClaims()" is the function import of the stored
procedure.

-doug


On Oct 30, 9:55 am, Jeremy Skinner <jer...@jeremyskinner.co.uk> wrote:
> How're you generating the IPagination instance?
>
> Jeremy
>
> 2009/10/30 doucol <doug.coll...@gmail.com>

Jeremy Skinner

unread,
Oct 30, 2009, 4:45:07 PM10/30/09
to mvccontri...@googlegroups.com
Does it make a difference if you convert it to alist first? ie ret.ToList().AsPagination() ?

Jeremy

2009/10/30 doucol <doug.c...@gmail.com>

Doug Collier

unread,
Oct 30, 2009, 8:37:17 PM10/30/09
to mvccontri...@googlegroups.com
Sorry, perhaps I don't understand, but, as far as I can tell, IEnumerable<> does not have a ToList() method.

Can you clarify?

Tim Scott

unread,
Oct 30, 2009, 9:52:41 PM10/30/09
to mvccontri...@googlegroups.com
Add using System.Linq; to your file.

Doug Collier

unread,
Oct 31, 2009, 12:23:59 AM10/31/09
to mvccontri...@googlegroups.com
<laughing> yeah, still getting used to these linq extensions - it works now - thanks much.

however, i think i'll try to rework this so that the stored procedure populates another table with the date-range of data and then have the grid and pager work off of this other table...or construct another view.  this should allow the grid and pager to actually retrieve just the page of data out of the larger data set.

thanks again,
-doug
Reply all
Reply to author
Forward
0 new messages