Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Entity framework EF lazy loading:EntityType未声明名称为的导航属性_Entity Framework_Lazy Loading - Fatal编程技术网

Entity framework EF lazy loading:EntityType未声明名称为的导航属性

Entity framework EF lazy loading:EntityType未声明名称为的导航属性,entity-framework,lazy-loading,Entity Framework,Lazy Loading,我有一个类似这样的类结构: public class Customer{ public AgreementDetails Agreement { get; set; } } [ComplexType] public class AgreementDetails{ public int SalesPersonId { get; set; } [ForeignKey("SalesPersonId")] [NotMapped] public virt

我有一个类似这样的类结构:

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属性来取消显示Sales person详细信息,但属性为null,通常用于导航属性,这可以避免使用。Include方法,但在我的情况下它不起作用,因此查询为空

List<Customer> res = db.Customers.Include(c=>c.Agreement.Sales).ToList();
List res=db.Customers.Include(c=>c.Agreement.Sales.ToList();
例外情况是:

指定的包含路径无效。实体类型 “CodeFirstNamespace.Customer”未声明导航属性 名称为“协议”


我找到了答案:复杂类型不应该包含导航属性(以及外键)。