DeductionItems和主表配了级联删除,代码执行时会抛The relationship could not be changed because one or more of the foreign-key properties is non-nullable
如果去掉对从表的遍历就能成功删除,为什么会这样呢

解决方案 »

  1.   

    因为 DeductionItems 是 NULL 的 
      

  2.   

    DeductionItems 不是 NULL,是null的话反而可以成功删除
      

  3.   

    可能是foreach延迟执行导致的
      

  4.   

    不是foreach的原因,只有我通过导航属性把从表数据拿出来了都会这样(ps:var test=a.DeductionItems)
      

  5.   

    你改成for试试啊。
    foreach,就是不能修改当前实体的。