开发者

LINQ to SQL SubmitChangess() progress

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);
});


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++;
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜