views:

371

answers:

1

How to delete multiple records in linq with multiple conditions?

A: 

Not sure to understand your problem, but you can get typed object you need with a simple linq query, then remove them on iteration

var objectsToRemove = ...
using(Datacontext context = ...)
{
     using(TransactionScope scope = new TransactionScope())
     {
      objectsToRemove.foreach(entity=>
      {
         context.YourEntities.Attach(entity);
     context.YourEntities.DeleteOnSubmit(entity);
     context.SubmitChanges();    
      }); 
       scope.Complete();
     } 
}
Xstahef