[英]Eager Load Nested One-to-One Navigation Property
假设我有以下课程:
class Person
{
public int Id { get; set; }
public Address Address { get; set; }
}
class Address
{
public int Id { get; set; }
public Country Country { get; set; }
}
class Country
{
public int Id { get; set; }
public Name { get; set; }
}
现在,使用存储库,我从数据库中加载了一个人,但我也希望加载它的Address
属性和address的Country
属性。 我使用以下代码加载即时导航属性。
context.Entry(person).Reference(p => p.Address).Load();
现在,我的问题是如何加载已加载的Address
属性的Country
导航属性。 谁可以帮我这个事? 非常感谢。
获取引用的查询,然后调用include(但是您将必须枚举.ToArray()
,因为将没有Load()
方法要调用-不用担心,EF会连接原始实体的nav属性):
var navPropQuery = context.Entry(person).Reference(p => p.Address).Query()
as System.Data.Objects.ObjectQuery<Address>;
navPropQuery.Include( "Country" ).ToArray();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.