The method 'Skip' is only supported for sorted input in LINQ to Entities

前端 未结 4 1092
暖寄归人
暖寄归人 2021-02-12 10:18

What could be causing this problem?

public ActionResult Index(int page = 0)
{
    const int pageSize = 3;
    var areas = repo.FindAllAreas();
    var paginatedA         


        
4条回答
  •  孤独总比滥情好
    2021-02-12 10:37

    I wanted to validate this by running the SQL equivalent of a similar LINQ skip/take query.

    SELECT * FROM [table]
    --order by [column] //omitted!
    OFFSET 10 ROWS
    FETCH NEXT 15 rows only
    

    Note that when the order-by clause is omitted, the SQL error is much less informative:

    "Invalid usage of the option NEXT in the FETCH statement."
    

    So the "sorted input" is actually required on the database-level. Kudos to LINQ for helping developers write advanced SQL statements!

提交回复
热议问题