Pagnation with LINQ to entities

74 views Asked by At

I have a problem, I'm trying to use a helper-class for a MVC project. And I get error that I must use OrderBy somehow.

this.AddRange(source.Skip(PageIndex * PageSize).Take(PageSize))

What to do? /M

1

There are 1 answers

3
Marc Gravell On BEST ANSWER

EF is precious about this (although LINQ-to-SQL would let you do it); just add an explicit OrderBy:

source.OrderBy(x=>x.SomeId).Skip(PageIndex * PageSize).Take(PageSize)

(or order by name, or whatever else makes sense)