views:

39

answers:

1

Hello

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  A: 

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)

Marc Gravell
Problem is that its a general class so it's used for different "tables" with different columns
molgan
So what is the data type here? Are you using generics or something? As far as I can see you have two choices; order it "at source", i.e. when you still know what the data is; or use reflection to identify the key and build your own `Expression<...>` to something useful. I'd recommend the first...
Marc Gravell
nvm :) I just order them before :)
molgan