我有一个称为地址的实体。地址包含一个称为房屋的复杂类型。房屋包含其占用者的参考。占领者是一个实体。
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; }
}
如果我使用lazyloading,一切正常,我可以访问所有属性。但是,我需要使用EagerLoading,因为在处理完Context之后很久才需要实体。
我试图使用此代码包括属性:
// DbSet is of type DbSet<Address>
List<Address> eagerLoadedEntity = DbSet.Where(a => a.Address.StartsWith("a"))
.Include(a => a.House.Occupants).ToList();
我收到以下错误:
指定的包含路径无效。EntityType“地址”未声明名称为“房屋”的导航属性。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句