I have a LINQ query that is created in parts like this:
var initialQuery = from item in MyContext where xxx == yyy select item;
var furtherQuery = from item in initialQuery where bla == foo select new { some stuff };
var yetAnotherQuery = (from item in furtherQuery ...)
.OrderBy(my_condition);
var stillAnotherQuery = (from item in yetAnotherQuery
select item.data_I_care_about)
.Distinct();
var finalQuery = stillAnotherQuery.Skip(PageIndex).Take(PageSize);
But I get an exception when called Skip(), saying the request is not ordered! So it’s obvious that what is stated in my comment on the code above and the link to the SO question is not entirely true. In fact, another SO answer indicates that keeping this order is not guaranteed.
Does anyone know a good way to do what I'm trying to accomplish?
I thought that I simply included a ROW_NUMBERin my intermediate results and ordering it at the very end, but I cannot find a way to get this ROW_NUMBERin my results through LINQ.
SO questions, ROW_NUMBER, , .
, .
- (LINQ-friendly) ?
UPDATE
, Distinct() OrderBy().
, .
, .
myRank | myData
-------+--------
3 | A
1 | B
2 | A
, myRank, , , myData, , :
var query = from item in MyTable
select item;
query = query.OrderBy(item => item.myRank);
var derivedQuery = from item in query
select item.myData;
derivedQuery = derivedQuery.Distinct();
OrderBy() Distinct(), . , myRank Distinct().
, , .
, , ?