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.

2 thoughts on “Bulk Operations using Linq To SQL

  1. Pingback: Batch Update using Linq To SQL « devioblog

  2. Pingback: Series: Batch Insert and Batch Update using Linq To SQL « devioblog

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 )

Facebook photo

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

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.