LINQ to SQL SubmitChangess()进度 [英] LINQ to SQL SubmitChangess() progress

查看:103
本文介绍了LINQ to SQL SubmitChangess()进度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用LINQ进行SQL将旧的DBF文件导入MSSQL. 我正在读取所有行,并使用ctx.MyTable.InsertOnSubmit(row)

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)

读取阶段完成后,我有大约100000个待处理的插入内容. ctx.SubmitChanges()自然要花很长时间.

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

有什么方法可以追踪ctx.submitchanges()的进度吗? ctx.Log可以用于此目的吗?

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

更新:是否可以使用ctx.GetChangeSet().Inserts.Count并使用日志"跟踪插入语句?

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

ctx.SubmitChanges()分成较小的块对我来说不起作用,因为我需要全部或全部不交易.

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

更新2: 我找到了不错的ActionTextWriter类,该类将尝试计算插入次数.

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

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

推荐答案

我已经通过解析日志并使用ActionTextWriter来获取进度信息

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

这篇关于LINQ to SQL SubmitChangess()进度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆