线性查询 TOP 11-20

问题描述 投票:1回答:3

我在执行这个查询时得到一个错误。

在LINQ to Entities中,'Skip'方法只支持排序输入。'OrderBy'方法必须在'Skip'方法之前被调用。

var data = (from xx in VDC.SURVEY_EMAIL_BLAST
               where xx.USER_ID == userid
               orderby xx.ID
               select xx.TEMPLATE_ID).Distinct().Skip(10).Take(10));

事实上,我已经在使用 "跳过 "方法了。OrderBy 但是,我得到了错误。

c# .net sql-server linq sql-order-by
3个回答
6
投票

试试指定 OrderBy 之前 Skip,像这样。

var data = (from xx in VDC.SURVEY_EMAIL_BLAST
            where xx.USER_ID == userid
            select xx.TEMPLATE_ID).Distinct()
                                  .OrderBy(x => x)
                                  .Skip(10).Take(10));

4
投票

它告诉你到底是什么问题,以及如何处理它。

var data = (from xx in VDC.SURVEY_EMAIL_BLAST
                                where xx.USER_ID == userid
                                orderby xx.ID
                                select xx.TEMPLATE_ID)
           .Distinct()
           .OrderBy(x => x)
           .Skip(10)
           .Take(10));

-1
投票

试试这个

  data = (from xx in VDC.SURVEY_EMAIL_BLAST
                            where xx.USER_ID == userid
                            orderby xx.ID
                            select xx.TEMPLATE_ID).Distinct().Skip(10).Take(10);

  data1=data.ToList(); // it will fetch only 11-20.
© www.soinside.com 2019 - 2024. All rights reserved.