【发布时间】:2012-10-12 20:22:29
【问题描述】:
我有一个类似这样的类结构:
public class Customer{
public AgreementDetails Agreement { get; set; }
}
[ComplexType]
public class AgreementDetails{
public int SalesPersonId { get; set; }
[ForeignKey("SalesPersonId")]
[NotMapped]
public virtual SalesPerson Sales { get; set; }
}
public class SalesPerson
{
...
}
当我显示客户列表时,我正在调用 Sales 属性以显示销售人员详细信息,但属性为 null,通常对于导航属性,可以避免使用 .Include 方法,但在我的情况下它不起作用,所以查询是
List<Customer> res = db.Customers.Include(c=>c.Agreement.Sales).ToList();
例外是:
指定的包含路径无效。实体类型 “CodeFirstNamespace.Customer”未声明导航属性 名称为“协议”。
【问题讨论】:
标签: entity-framework lazy-loading