假设您有这样的代码。
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.
}
但我想知道有没有办法轻松删除对象列表?我不想用foreach
list 一个一个来做。谢谢。