我正在尝试从 MySQL 数据库中删除分配。这样做时,我将删除所有元素和虚假内容,如下所示。问题是,当它到达 deleteboguses 方法中的 for 循环时,它会引发异常“EntityCommandExecutionException”,任何想法为什么会这样做?我究竟做错了什么?
public static void DeleteAssignment(int id)
{
var deleteAssignment = from assignment in context.assignment
where assignment.id == id
select assignment;
DeleteElement(id);
foreach (assignment a in deleteAssignment)
{
context.assignment.DeleteObject(a);
}
context.SaveChanges();
}
public static void DeleteElement(int id)
{
var deleteElement = from element in context.element
where element.assId == id
select element;
foreach(var e in deleteElement)
{
DeleteBoguses(e.id);
context.element.DeleteObject(e);
}
context.SaveChanges();
}
public static void DeleteBoguses(int id)
{
var deleteBogus = from b in context.bogus
where b.elementId == id
select b;
foreach(var b in deleteBogus)
{
context.bogus.DeleteObject(b);
}
context.SaveChanges();
}