[英]How to Delete Orphaned Records
I'm trying to use GraphDiff and Entity Framework to update a set of records across multiple tables.我正在尝试使用 GraphDiff 和实体框架来跨多个表更新一组记录。 Everything works except I need to delete the orphaned record for any of the owned entities that may have been replaced.
除了我需要删除任何可能已被替换的拥有实体的孤立记录外,一切正常。 What am I missing as I expect that this behavior is common and I just need to figure out how to configure the context or graph appropriately.
我缺少什么,因为我希望这种行为很常见,我只需要弄清楚如何适当地配置上下文或图形。 Here is my sample code:
这是我的示例代码:
using (EfDataContext ctx = new EfDataContext())
{
try
{
ctx.Database.Log = msg => _sysLogObject.Debug(msg);
ctx.UpdateGraph(assay, map => map
.OwnedCollection(p => p.Imagings, with => with
.OwnedEntity(p => p.ImagingCellType))
.OwnedEntity(p => p.DisplayTemplate)
.OwnedEntity(p => p.ExportTemplate)
.OwnedEntity(p => p.PrintTemplate)
);
ctx.SaveChanges();
success = true;
}
catch (Exception ex)
{
_sysLogObject.Error(ex);
throw;
}
}
Disclaimer : I'm the owner of the project Entity Framework GraphDiff免责声明:我是Entity Framework GraphDiff项目的所有者
We also got the same question by email. email 也有同样的问题。 The answer was:
答案是:
The child must have a navigation property toward the parent to make it work.
子级必须具有朝向父级的导航属性才能使其工作。 Otherwise, the entity is just skipped by the ChangeTracker from Entity Framework.
否则,实体框架中的 ChangeTracker 只会跳过实体。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.