Linq 获取EF中的下一条记录,其中记录不是按ID排序的

Linq 获取EF中的下一条记录,其中记录不是按ID排序的,linq,entity-framework,linq-to-entities,entity-framework-6,entity-sql,Linq,Entity Framework,Linq To Entities,Entity Framework 6,Entity Sql,我需要编写一个查询,返回一条记录,而这条记录将是提供ID的记录中的下一条记录 var x = GetNextRecord(int recordId); 问题在于数据不是按ID排序的,而是按其他一些标准排序的。查询示例: SELECT * FROM SomeTable WHERE conditions ORDER BY column1, column2, column3 例如,此查询返回25条记录。假设在这个结果集中,ID=42的记录是第7条记录。这就意味着我们需要返回第8个记录 等效的Lin

我需要编写一个查询,返回一条记录,而这条记录将是提供ID的记录中的下一条记录

var x = GetNextRecord(int recordId);
问题在于数据不是按ID排序的,而是按其他一些标准排序的。查询示例:

SELECT * FROM SomeTable
WHERE conditions
ORDER BY column1, column2, column3
例如,此查询返回25条记录。假设在这个结果集中,ID=42的记录是第7条记录。这就意味着我们需要返回第8个记录

等效的Linq是

list.OrderBy(x => x.a)
    .ThenBy(x => x.b)
    .ThenBy(x=> x.c)
    .SkipWhile(x => x.Id != id) // we skip records until we arrive to the record with given Id
    .Take(2) // we take the next two records (current and the next one)
    .LastOrDefault() // and finally we take the last one, which is our next record;

但是,此查询不适用于linq to entities,因此L2E(或EntitySQL)中的等效项是什么?

为什么不适用于linq to entities?@DavidG,因为linq to entities中不支持SkipWhile。