簡體   English   中英

Linq的等待操作超時異常

[英]The wait operation timed out exception with Linq

我需要開發一個簡單的Windows桌面應用程序,它將在單個表MDF中加載CSV文件,從中生成一些報告,然后刪除數據。 CSV文件可能包含數百萬條記錄...

當我嘗試執行代碼以在dbGridView中顯示數據時,拋出異常“等待操作超時”。

  db dbEntities = new db();

    var ds = (from tbl in db.tbl_csv
              orderby f1
              select new
              {
                  f1= tbl.f1,
                  f2 = tbl.f2,
                  f3= tbl.f3,
                  f4= tbl.f4,
                  f5= tbl.f5,
                  f6= tbl.f6,
                  f7= tbl.f7,
                  f8= tbl.f8
              }
                  );
    var bds = ds.ToList();
    return Helpers.ToDataSet(bds);

如果csv包含少量數據,則此方法有效,但是當它具有70-80k以上的記錄時,將引發異常。

有什么解決方法嗎?

一次讀取n條記錄。 例如

int totalRecords = ds.Count();
int n = 100;
int chunksRead = 0;
int recordsRead = 0;

while(recordsRead < totalRecords)
{
    ds.Skip(recordsRead).Take(n);
    // process n records
    ...
    chunksRead++;
    recordsRead = chunksRead * n;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM