开发者社区 问答 正文

EF用导航熟悉遍历从表时,删除主表出错

1 var entitys= Repository.Table.Where(a => ids.Contains(a.UUID)).ToList(); 2 entitys.ForEach(a => 3 { 4 foreach (var deductionitem in a.Deductionitems){} 5 DoDelete(a); 6 } DeductionItems和主表配了级联删除,代码执行时会抛The relationship could not be changed because one or more of the foreign-key properties is non-nullable 如果去掉对从表的遍历就能成功删除,为什么会这样呢

展开
收起
泡沫小迪 2020-05-29 15:58:05 638 分享 版权
1 条回答
写回答
取消 提交回答
  • 遍历子表后,EF无法分辨该记录是否要保留。所有需要手动删除从表,不能再依赖级联删除

    2020-05-29 15:58:12
    赞同 展开评论
问答地址: