0

如果我使用普通查询,我有一个大表,它有一个超时异常。所以我想选择前1000个然后输出,下一步是从1001到2000检索并记录它等等。

我不确定如何在查询中添加参数。

int pageNumer = 0;
var query = DBContext.MyTable.Where(c=>c.FacilityID == facilityID)
 .OrderBy(c=>c.FilePath)
 .Skip(pageNumer*1000)
 .Take(1000);

foreach(var x in query)
{
     // Console.WriteLine(x.Name);
}
   // I want pageNumber is incremented until it goes to the bottom of the table.
   // I don't know how many records in the table.
4

1 回答 1

0

试试这个:

int pageNumber = 0;
bool hasHitEnd = false;

while (!hasHitEnd)
{
   var query = DBContext.MyTable.Where(c=>c.FacilityID == facilityID)
    .OrderBy(c=>c.FilePath)
    .Skip(pageNumber*1000)
    .Take(1000);

   foreach(var x in query)
   {
        // Do something
   }

   if (query.Count < 1000)
   {
      hasHitEnd = true;
   }

   pageNumber++;
}
于 2013-02-05T16:56:39.317 回答