删除DataContext中的批量对象

时间:2009-12-11 09:10:34

标签: c# linq

无法删除

等批量对象
List<Person> prn = new List<Person>();
prn.Add(new Person { Id = "P007", name = "Andrew"});
prn.Add(new Person { Id = "P009", name = "Bernold"});
prn.Add(new Person { Id = "P010", name = "Hare"});
PersonDB.Persons.DeleteAllOnSubmit(prn);
PersonDB.SubmitChanges();

我收到错误

Cannot remove an entity that has not been attached.

1 个答案:

答案 0 :(得分:1)

在删除前尝试attaching对象到上下文:

PersonDB.Persons.AttachAll(prn, true);