【问题标题】:How can I get a specific number of records when performing an IEnumerable query? [duplicate]执行 IEnumerable 查询时如何获取特定数量的记录? [复制]
【发布时间】:2016-09-19 11:20:59
【问题描述】:

我有一个IEnumerable,目前正在使用它来获取数据库中的所有记录。

IEnumerable<Item> items = dbContext.Items.Include(i => i.itemField).AsEnumerable();

有什么方法可以让我从数据库中只获取特定数量的项目,比如下面的伪代码?

//This would get records 30 - 40 in the database items = items.Where(i => i.otherField != null).GetNumberOfRecords(30, 40);

【问题讨论】:

    标签: c# mysql entity-framework ienumerable


    【解决方案1】:

    当然!

    你可以使用:

    items  = items.Where(i => i.OtherField != null).Skip(30).Take(10).ToList();
    

    或者没有你喜欢的 ToList() :)

    【讨论】:

    • 成功了。非常欢呼。 :)
    • 来杯啤酒就好了 ;)
    猜你喜欢
    • 2014-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-29
    • 2011-05-28
    • 1970-01-01
    • 2016-06-13
    • 2021-05-16
    相关资源
    最近更新 更多