是否有可能使用 LinQ 和 Take() 从数据库 table 中获取 100 条记录然后其他 100 条记录

Is there a possibility to take 100 records then other 100 record from database table using LinQ and Take()

使用 Code First,Oracle 数据库 如果数据量很大,我需要select前100条记录, 但我还需要有机会获得剩余的记录,那么如何从 101 开始获取接下来的 100 条记录?

是否可以使用 Linq Take() 来实现?

List<int> myList = new List<int>();
List<int> newList = new List<int>();

myList = DBContext.MyTable.Where(x=>x.ID == someParam).Select(x=>x.ID).toList();
int recodCount = myList.Count();

if (recodCount > 1000)
{
    newList.AddRange(myList.Take(100));
}
else
{
    newList.AddRange(myList);
}

我想你需要分页你需要定义 pageIndex 和 pageSize

myList = DBContext.MyTable
                  .Where(x=>x.ID == someParam)
                  .Skip((pageIndex - 1) * pageSize)
                  .Take(pageSize);

但是,如果您只想跳过 100,那么您缺少的是 SkipEnumerable.Skip Method

就像 Tim 所说的那样,不要在请求时调用 ToList() 这将 select 内存中的所有内容。也不要调用 Count() 来检查 if(count > 100)。你应该这样做: if(myList.Skip(number).Any()) 如果你的 collection 的记录多于 number.