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 为什么在使用LINQ to Entities Include()时不包括我的引用属性之一?_Entity Framework_Entity Framework 4.1_Ef Code First - Fatal编程技术网

Entity framework 为什么在使用LINQ to Entities Include()时不包括我的引用属性之一?

Entity framework 为什么在使用LINQ to Entities Include()时不包括我的引用属性之一?,entity-framework,entity-framework-4.1,ef-code-first,Entity Framework,Entity Framework 4.1,Ef Code First,我有以下属性声明和映射摘要类: public class Consumer: AuditableEntity { public virtual Consumer Parent { get; set; } public virtual User User { get; set; } public virtual Role Role { get; set; } public virtual ICollection<Consumer> Consumers {

我有以下属性声明和映射摘要类:

public class Consumer: AuditableEntity
{
    public virtual Consumer Parent { get; set; }
    public virtual User User { get; set; }
    public virtual Role Role { get; set; }
    public virtual ICollection<Consumer> Consumers { get; set; }
}

public ConsumerMap()
{
    HasRequired(t => t.Role)
        .WithMany(t => t.Consumers)
        .Map(a => a.MapKey("RoleId"))
        .WillCascadeOnDelete(false);
    HasRequired(t => t.User)
        .WithOptional(t => t.Consumer)
        .Map(a => a.MapKey("UserId"))
        .WillCascadeOnDelete(false);
}

如何执行最后一段代码中的查询?通过直接应用ToList还是添加Select或介于两者之间的内容?@Slauma我将另一个Where“附加”到调用最后一个代码段的函数调用,即ListAll.Whereblah.ToList第二个映射看起来不正确。这是一个一对一的映射,但您显然是将密钥映射到一个外键UserId,它可能不是使用者中的主键,或者是?不过这个名字会很奇怪。EF中不支持外键一对一关联。对此有任何解决方案吗??我也有同样的问题。
return CurrentDbContext.Consumers.Include("User").Include("Role").Where(e => !e.IsDeleted);