none
Call to RemoveAll.... individual DELETE statements RRS feed

  • Question

  • Hi everyone,

     

    I've just tried the following straightforward LINQ statement, and was surprised by the SQL generated:

     

    dataContext.ContentTag.RemoveAll(from s in dataContext.ContentTag where blah select s );

    dataContext.SubmitChanges();

     

    I had expected, as we've got deferred execution, that LINQ would turn this into something like

     

    DELETE FROM ContentTag WHERE PrimaryKey IN (SELECT PrimaryKey FROM ContentTag WHERE blah)

     

    or such like....

     

    Instead, I get one SELECT statement, followed by hundreds of individual DELETE statements. Is there any way to get this behaviour, or am I going to have to use ExecuteQuery and write my own??

     

    Thanks

    Saturday, May 3, 2008 2:31 PM

Answers

  • LINQ to SQL does not generate any batch style delete commands.  SubmitChanges only sends individual SQL commands for each object.  If you want to affect objects in bulk you'll need a stored procedure or use ExecuteQuery.

     

    Monday, May 5, 2008 6:06 PM
    Moderator