gpt4 book ai didi

entity-framework - 如何删除孤立记录

转载 作者:行者123 更新时间:2023-12-03 07:21:49 25 4
gpt4 key购买 nike

我正在尝试使用 GraphDiff 和 Entity Framework 来更新多个表中的一组记录。一切正常,除了我需要删除任何可能已被替换的拥有实体的孤立记录。我缺少什么,因为我期望这种行为很常见,我只需要弄清楚如何适本地配置上下文或图形。这是我的示例代码:

        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;
}
}

最佳答案

免责声明:我是该项目的所有者 Entity Framework GraphDiff

我们也通过电子邮件收到了同样的问题。答案是:

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.

关于entity-framework - 如何删除孤立记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58702313/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com