Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I have some problems with LINQ expression, OrderBy(), Skip(), Take() works incorrect

I have LINQ expression like

var a = ctx.EntitySet
        .OrderByDescending(t => t.Property)
        .Skip(pageIndex * size) 
        .Take(size);

OrderBy() should call before Skip() and Take(), but sorting happens at the end. Can I solve this problem?

Sorry, many people didn't understand my question. Query runs without any errors, but I want

//It is I want
1) Sorting ALL data
2) Use Skip() and Take()

What I have in result if I do like at my example: 1) Skip() 2) Take() 3) Sorting only taked elements!

like image 846
DraggonZ Avatar asked Nov 05 '22 14:11

DraggonZ


1 Answers

i don't know why , but somehow it works for me , hope it helps you

var a1 = from p in ctx.EntitySet
        .OrderByDescending(t => t.Property)
        select p;

var a2 = from p in a1
        .Skip(pageIndex * size) 
        .Take(size)
        select p;
like image 114
Nima Derakhshanjan Avatar answered Dec 13 '22 18:12

Nima Derakhshanjan