【问题标题】:LINQ to SQL SubmitChangess() progressLINQ to SQL SubmitChanges() 进度
【发布时间】:2010-12-30 15:27:38
【问题描述】:

我正在使用 LINQ to SQL 将旧的 DBF 文件导入 MSSQL。 我正在读取所有行并将它们添加到数据库中使用ctx.MyTable.InsertOnSubmit(row)

阅读阶段完成后,我有大约 100 000 个待处理的插入。 ctx.SubmitChanges()自然要等很久。

有没有办法跟踪ctx.submitchanges() 的进度? ctx.Log 可以用于此目的吗?

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

ctx.SubmitChanges() 分成更小的块对我不起作用,因为我需要交易,要么全部要么全部。

更新 2: 我找到了不错的 ActionTextWriter 类,我将使用它来计算插入次数。

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

更新 3:

我已经构建了第一个代码原型,它没有经过优化。它似乎正在工作:)

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

【问题讨论】:

标签: c# linq-to-sql progress submitchanges


【解决方案1】:

我已经设法通过解析日志和使用 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++;
});

【讨论】:

    猜你喜欢
    • 2013-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多