如果我仅更改零件对象的值,它就可以正常工作,但是如果删除一个零件对象,则会出现Null指针异常。似乎已删除的零件对象被赋予了状态Entity.Modified
(为什么没有Entity.Deleted
BTW?)并且缺少指向整体的指针?
var modifiedParts = context.ChangeTracker.Entries<Parts>()
.Where(x => x.State == EntityState.Modified || x.State == EntityState.Added || x.State == EntityState.Deleted);
foreach (var part in modifiedParts)
{
part.Entity.Whole.ModifiedTimeStamp = DateTime.Now;
}