如何从 entity framework 的列表中获取以下项目?
How can I get the following items from a list with entity framework?
我有一个非常大的列表,我想提取 50 个项目的一部分,我将对其执行以下操作:
try
{
using (var context = new ccoFinalEntities())
{
return context.sales
.Where(p => true == p.status && myID == p.id)
.Take(50)
.ToList();
}
}
catch
{
return null;
}
我假设这将 return 我的前 50 个项目,我的问题是:
在完全提取列表之前,我怎样才能得到下一个 50 等等?
欢迎大家提出意见或建议
public List<Item> GetDate(int page, int size = 50)
{
try
{
using (var context = new ccoFinalEntities())
{
return context.sales.Where(p => true == p.status && myID == p.id)
.Skip(page * size).Take(size).ToList();
}
}
catch
{
return null;
}
}
然后调用:
GetData(0);
GetData(1);
GetData(2);
GetData(3);
.......
Skip
先忽略 page * size
(1 * 50, 2 * 50, ...) 项和 Take
size
(50) 项
我有一个非常大的列表,我想提取 50 个项目的一部分,我将对其执行以下操作:
try
{
using (var context = new ccoFinalEntities())
{
return context.sales
.Where(p => true == p.status && myID == p.id)
.Take(50)
.ToList();
}
}
catch
{
return null;
}
我假设这将 return 我的前 50 个项目,我的问题是:
在完全提取列表之前,我怎样才能得到下一个 50 等等?
欢迎大家提出意见或建议
public List<Item> GetDate(int page, int size = 50)
{
try
{
using (var context = new ccoFinalEntities())
{
return context.sales.Where(p => true == p.status && myID == p.id)
.Skip(page * size).Take(size).ToList();
}
}
catch
{
return null;
}
}
然后调用:
GetData(0);
GetData(1);
GetData(2);
GetData(3);
.......
Skip
先忽略 page * size
(1 * 50, 2 * 50, ...) 项和 Take
size
(50) 项