如何告诉DBContext的Find方法它应该急切地加载导航属性/实体?
我有以下代码删除与相关辅助实体的关联:
Person primary = db.People.Find(Id);
if (primary == null)
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
// This line is required to load the related entity
db.Entry(primary).Reference("Secondary").Load();
primary.Secondary = null;
db.SaveChanges();
Run Code Online (Sandbox Code Playgroud)
我不得不添加这条线db.Entry(primary).Reference("Secondary").Load();以使其正常工作.我理解这是因为实体框架正在使用延迟加载.我可以在Find方法中覆盖它,并通过使用Find方法的Eager版本摆脱额外的行吗?