Bulk Operations using Linq To SQL

I tried to figure out how to implement bulk operations (batch insert, batch update) using Linq To SQL.

The bulk operation should operate on the existing Linq To SQL infrastructure, namely

  • the L2S DataContext
  • the class declarations of the data model generated by the .dbml designer

For example, the batch operation would be written like this:

var database = new DataContext();

var update = new BatchUpdate<MyTable>()
        .Set(t => t.SomeText, t => t.SomeText + " updated")
        .Set(t => t.AnotherText, t => t.AnotherText + " modified")
        .Where(t => t.ID < 10);

var recordsUpdated = database.Execute(update);

Before blogging on this topic, I found that other people also worked on this problem:

The next couple of blogs will sketch the solution I implemented.

Advertisements

2 Responses to Bulk Operations using Linq To SQL

  1. […] Given the definition of a Batch Update command […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: