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:
- Linq To SQL batch update method
- Batch Updates and Deletes with Linq To SQL
- Bulk INSERT/UPDATE/DELETE in Linq To SQL
- PLINQO for Linq To SQL
The next couple of blogs will sketch the solution I implemented.