var entitys= Repository.Table.Where(a => ids.Contains(a.UUID)).ToList();
 entitys.ForEach(a =>
 {
   foreach (var deductionitem in a.Deductionitems){}
   DoDelete(a);
}

 

DeductionItems和主表配了级联删除,代码执行时会抛The relationship could not be changed because one or more of the foreign-key properties is non-nullable

解决方法:

遍历子表后,EF无法分辨该记录是否要保留。所以需要手动删除从表,不能再依赖级联删除

版权声明:本文为Cyril-hcj原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/Cyril-hcj/p/12975432.html