There is something like DbSet <T> .RemoveWhere (Predicate <T>)
Possible duplicate:
LINQ bulk deletion for objects
I need to delete some objects by condition. For example, delete all order items having an amount 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 these elements and then delete them one by one, for example:
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 additional work will be done. Did I miss something?
+6
1 answer
You can use the EntityFramework.Extended plugin on GitHub, which supports Batch Update and Uninstall .
+3