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

前端 未结 4 761
执笔经年
执笔经年 2021-02-12 10:07

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:52

    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!

提交回复
热议问题