Archive for the ‘Databases’ Category

Linq to sql, ctx.submitchanges progress

January 2, 2011 1 comment

Linq to sql provides no default mechanism for tracking progress of the ctx.submitchanges() method.

This can be troublesome if you are using batch import with linq to sql (which is not the best practice by itself).

I asked question on the stackoverflow

Response to the similar question was to divide inserts into multiple ctx.submitchanges() methods. This would work fine, but I needed transactions (all inserts or none)

I can get total number of inserts by using ctx.GetChangeSet().Inserts.Count;

Using ActionTextWriter class I found on

I was able to track progress of the inserts using following snippet of code

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

Linq to sql will write to the log file every sql statement. if the statements begins with INSERT INTO, that’s new insert.

Evertything I need for the progress bar is here 🙂

Also, performance wise, I’m reporting progress for every 10 000 inserted records. Refreshing screen too often can be slow sometimes.


Why foreign keys are important

October 14, 2010 Leave a comment

On one project, about two years ago, we have decided that we didn’t need relations in relational database.

So we deleted them. We just used tables for storage, almost like flat files.

At first, programming was easy, but then, we started implementing logic for relational integrity, and that was no easy task. We had to implement every “relation” manually in code…

After a while, we started using relations again. Relations are there for a reason. Sometimes it’s a pain in the neck to deal with them. But, it’s even worse without them.

In relational databases, just use relations. Many smart people have figured that out. Smarter than me, that’s for sure.

P.S. document databases also have some kind of “nesting” relations built-in.

Categories: Databases, Software design