如何告诉DBContext的Find方法它应该急切地加载导航属性/实体?如何使用DBContext指定急切加载查找方法
我有下面的代码删除联想到相关的辅助实体:
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();
我不得不添加行db.Entry(primary).Reference("Secondary").Load();
得到它的工作。我明白这是因为实体框架使用延迟加载。我可以在Find方法中覆盖它,并通过使用Eager版本的Find方法摆脱多余的行吗?