Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there something like DbSet<T>.RemoveWhere(Predicate<T>) [duplicate]

Possible Duplicate:
Bulk-deleting in LINQ to Entities

I need to remove some entities by condition. E.g., remove all order items having quantity less than 1:

var orderId = 10; // any order Id
context.OrderItems.RemoveWhere(item => item.OrderId == orderId && item.Quantity < 1.0);

I know, that I can select those items and then remove them one-by-one like this:

var itemsToRemove = context.OrderItems.Where(item => item.OrderId == orderId && item.Quantity < 1.0).ToArray();

foreach (var item in itemsToRemove)
  context.OrderItems.Remove(item);

But this is very unlikely, because extra work will take place. Am I missed something?

like image 954
Dennis Avatar asked Jul 25 '12 11:07

Dennis


1 Answers

You could use the EntityFramework.Extended plugin on GitHub which has support for Batch Update and Delete.

like image 196
James Avatar answered Oct 05 '22 00:10

James