我有一个名为Address的实体。一个地址包含一个名为House的复杂类型。房子包含对其居住者的参考。乘客是一个实体。复杂类型引用的EagerLoad实体
public class Address {
[key]
public int Id { get; set; }
public House House { get; set; }
}
家:
[ComplexType]
public class House
{
[Required]
public string HouseType { get; set; }
public IList<Occupant> Occupants { get; set; }
}
乘员
public class Occupant
{
[key]
public int Id { get; set; }
[Required]
public string Name { get; set; }
public virtual Address Address { get; set; }
}
如果我使用惰性加载一切工作正常,我可以访问所有属性。但是我需要使用EagerLoading,因为在处理Context之后很长时间需要实体。
我已经tryed,包括使用此代码的属性:
// DbSet is of type DbSet<Address>
List<Address> eagerLoadedEntity = DbSet.Where(a => a.Address.StartsWith("a"))
.Include(a => a.House.Occupants).ToList();
我得到以下错误:
A specified Include path is not valid. The EntityType 'Address' does not declare a navigation property with the name 'House'.
是什么类型'DbSet'? 'DbSet
'? – flindeberg哦....等等.....你有一个地址类内的地址类.... 也许你想在那里的房子? –
@AnestisKivranoglou是的,我想要那里的房子。 – CodeTower