[英]Can EF automatically delete data that is orphaned, where the parent is not deleted?
[英]How to Delete Orphaned Records
我正在嘗試使用 GraphDiff 和實體框架來跨多個表更新一組記錄。 除了我需要刪除任何可能已被替換的擁有實體的孤立記錄外,一切正常。 我缺少什么,因為我希望這種行為很常見,我只需要弄清楚如何適當地配置上下文或圖形。 這是我的示例代碼:
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項目的所有者
email 也有同樣的問題。 答案是:
子級必須具有朝向父級的導航屬性才能使其工作。 否則,實體框架中的 ChangeTracker 只會跳過實體。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.