3

Linq to Sql handles every insert/delete/update operation on an object with separate query. Is there a way to unite multiple operations in single query?

I know this is not possible with the default behavior of the framework. I'm looking for an extension method or workaround. I want to use the queries generated by Linq to Sql, not my own queries or stored procedures but unite multiple operations in a single round-trip to the database.

Branislav Abadjimarinov
  • 5,101
  • 3
  • 35
  • 44
  • Why does it matter if it's a single query, or if it is multiple queries which are sent together through one connection? – Aviad P. Dec 28 '09 at 12:23
  • Out-of-the-box: No. With extensions, yes. I have written a couple of datacontext extensions that will do that. Used to have it in a couple of articles in my old blog, but that one is offline for the moment. Will try to repost in my new blog sometime soon... – KristoferA Dec 28 '09 at 14:27
  • I want to submit all changes in a single query for performance reasons only. The fastest way I know is using SqlCommand with Bulk Insert and Bulk Delete but I want to use the linq programming model and leave the query generation to Linq to Sql. – Branislav Abadjimarinov Dec 28 '09 at 14:58

2 Answers2

2

look at this post : How to run a mass update/delete query in Linq?

It's a link to how to implement a batch update, batch delete ... hope it helps

Community
  • 1
  • 1
pdiddy
  • 6,217
  • 10
  • 50
  • 111
0

LINQ to SQL does not give you a way to specify a set-based update/delete against the database. The only alternative that I am aware of is to use use SQL directly, which you can do using the database context object.

Randy

Randy Minder
  • 47,200
  • 49
  • 204
  • 358