Say you have code like this .
using (CustomerContext db = new CustomerContext())
{
var foundCustList=db.Customers.Where(c=>c.State=='-1').ToList();//Find all the customer which State is -1
foreach(var c in foundCustList)
{
db.DeleteObject(c);
}
db.SaveChanges();//After all the customer is deleted, Commit.
}
But I want to know Is there any way to delete the list of object easily? I don’t want to use the foreach to do it one by one for a list . thanks.
You can use EntityFramework.Extended library, which is available from Nuget (don’t forget to add
using EntityFramework.Extensions;):Or you can write extension method manually:
Usage:
Or better one:
Usage: