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?
You could use the EntityFramework.Extended plugin on GitHub which has support for Batch Update and Delete.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With