LINQ to SQL SubmitChangess() progress

孤人 提交于 2019-12-19 21:45:11

问题


I'm using LINQ to SQLto import old DBF files into MSSQL. I'm reading all rows and adding them to database using ctx.MyTable.InsertOnSubmit(row)

After reading phase is completed I have around 100 000 pending inserts. ctx.SubmitChanges() naturally is taking a long time.

Is there any way to track progress of the ctx.submitchanges()? Can ctx.Log somehow be used for this purpose?

Update: Is it possible to use ctx.GetChangeSet().Inserts.Count and track insert statements using the Log?

Dividing ctx.SubmitChanges() into smaller chunks is not working for me, because I need transaction, all or nothing.

Update 2: I've found nice class ActionTextWriter using which I will try to count inserts.

http://damieng.com/blog/2008/07/30/linq-to-sql-log-to-debug-window-file-memory-or-multiple-writers

Update 3:

I've build first code prototype, it's not optimized. It seems to be working :)

ctx.Log = new ActionTextWriter(s => {
 counter += s.Split(' ').Count(w => w.ToUpper() == "INSERT");
 ReportProgress(counter);
});

回答1:


I've managed to get progress informations by parsing log and using ActionTextWriter

http://damieng.com/blog/2008/07/30/linq-to-sql-log-to-debug-window-file-memory-or-multiple-writers

ctx.Log = new ActionTextWriter(s => {
    if (s.StartsWith("INSERT INTO"))
        insertsCount++;
});


来源:https://stackoverflow.com/questions/4563828/linq-to-sql-submitchangess-progress

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!