I have some problems with the expression LINQ, OrderBy (), Skip (), Take () does not work correctly

I have a 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 did not understand my question. The request is executed without errors, but I want to

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

What do I have as a result, if I like in my example: 1) Skip () 2) Take () 3) Sort only the worked out elements!

+5
source share
3 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;
+2
source

Have you tried it

, , , .

var a = ctx.EntitySet
        .Skip(pageIndex * size) 
        .Take(size);

a = a.OrderByDescending(t => t.Property);

, , ,

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

, ....

0

team orders are not important in this example. it sorts your data first, and then your data will be collected.

0
source

All Articles