Skip to content Skip to sidebar Skip to footer

How Can I Get A Percentage Of Linq To Sql Submitchanges?

I wonder if anyone else has asked a similar question. Basically, I have a huge tree I'm building up in RAM using LINQ objects, and then I dump it all in one go using DataContext.Su

Solution 1:

I suggest you divide the calls you are doing, as they are sent in separate calls to the db anyway. This will also reduce the size of the transaction (which linq does when calling submitchanges).

If you divide them in 10 blocks of 75.000, you can provide a rough estimate on a 1/10 scale.

Update 1: After re-reading your post and your new comments, I think you should take a look at SqlBulkCopy instead. If you need to improve the time of the operation, that's the way to go. Check this related question/answer: What's the fastest way to bulk insert a lot of data in SQL Server (C# client)

Solution 2:

I was able to get percentage progress for ctx.submitchanges() by using ctx.Log and ActionTextWriter

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

more details are available at my blog post http://epandzo.wordpress.com/2011/01/02/linq-to-sql-ctx-submitchanges-progress/

and stackoverflow question LINQ to SQL SubmitChangess() progress

Solution 3:

This isn't ideal, but you could create another thread that periodically queries the table you're populating to count the number of records that have been inserted. I'm not sure how/if this will work if you are running in a transaction though, since there could be locking/etc.

Solution 4:

What I really think I need is a form of Bulk-Insert, however it appears that Linq doesn't support it.

Post a Comment for "How Can I Get A Percentage Of Linq To Sql Submitchanges?"