I have LINQ expression like
var a = ctx.EntitySet
.OrderByDescending(t => t.Property)
.Skip(pageIndex * size)
.Take(size);
OrderBy() sh开发者_JAVA百科ould 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!
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;
have you tried this
if you go for below solution it will first get the records and than does sorting on that records which may lead you to wrong result.
var a = ctx.EntitySet
.Skip(pageIndex * size)
.Take(size);
a = a.OrderByDescending(t => t.Property);
or
Following way you first doing sorting and than getting records after that, so by this way you can get the result you want , this is proper way to do
var a = ctx.EntitySet
.OrderByDescending(t => t.Property)
.Skip(pageIndex * size)
.Take(size);
But it always depends on your requirement what you want....
command orders in this sample is not Important. it will sort your data first and after that your data will be collected.
精彩评论