Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/260.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.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
C# includes()函数不';t工作_C#_Entity Framework_Ef Code First_Linq To Entities - Fatal编程技术网

C# includes()函数不';t工作

C# includes()函数不';t工作,c#,entity-framework,ef-code-first,linq-to-entities,C#,Entity Framework,Ef Code First,Linq To Entities,我首先使用EF 6和代码,但由于某种原因,当我试图从数据库收集icb列表时,依赖项(例如Station)不会作为填充对象(icb.Station)返回,只有stations ID。我有这种关系 公共类ICB { 公共ICB() { ICBResources=新列表(); } 公共int-ICBId{get;set;} 公共int-LevelId{get;set;} 公共虚拟站{get;set;} 公共字符串位置{get;set;} 调用的公共日期时间{get;set;} public DateT

我首先使用EF 6和代码,但由于某种原因,当我试图从数据库收集icb列表时,依赖项(例如Station)不会作为填充对象(icb.Station)返回,只有stations ID。我有这种关系

公共类ICB {

公共ICB()
{
ICBResources=新列表();
}
公共int-ICBId{get;set;}
公共int-LevelId{get;set;}
公共虚拟站{get;set;}
公共字符串位置{get;set;}
调用的公共日期时间{get;set;}
public DateTime TimeStarted{get;set;}
公共工作人员事故指挥官{get;set;}
公共工作人员行动指挥官{get;set;}
公职人员部门指挥官{get;set;}
公职人员部门指挥官2{get;set;}
公共工作人员指挥官支持官{get;set;}
公共工作人员安全官员{get;set;}
公共工作人员通讯官{get;set;}
公职人员{get;set;}
公职人员{get;set;}
公职人员办公室{get;set;}
公共虚拟公司公司{get;set;}
}
我该怎么做才能让所有成员都满员?他们只提供ID。 我正在使用.Include(),但不起作用

    public List<ICB> GetAllICBs(Company company, Station station = null)
    {
        if (station != null)
        {
            return GetDbSet<ICB>()
                .Include("ICBResources")
                .Include("Station")
                .Where(i => i.Company.CompanyId == company.CompanyId 
                    && i.Station.StationId == station.StationId)
                .OrderByDescending(o => o.TimeStarted).ToList();
        }
        else
        {
            return GetDbSet<ICB>()
                .Include("ICBResources")
                .Include("Station")
                .Where(i => i.Company.CompanyId == company.CompanyId)
                .OrderByDescending(o => o.TimeStarted).ToList();
        }
    }
公共列表GetAllICBs(公司,站点=null)
{
如果(站!=null)
{
返回GetDbSet()
.包括(“ICB资源”)
.包括(“车站”)
.其中(i=>i.Company.CompanyId==Company.CompanyId
&&i.Station.StationId==Station.StationId)
.OrderByDescending(o=>o.TimeStarted).ToList();
}
其他的
{
返回GetDbSet()
.包括(“ICB资源”)
.包括(“车站”)
.其中(i=>i.Company.CompanyId==Company.CompanyId)
.OrderByDescending(o=>o.TimeStarted).ToList();
}
}

您好,您的存储库中是否有GetDbSet方法?如果是,则可能返回没有相关表的数据,您应该使用存储库中的早期包含,即:

IQueryable icb = db.ICB.Include("ICBResources");

include方法上我的属性的名称错误


感谢您的帮助。

这是我的dbContext
受保护的TargetDbContext{get{return(TargetDbContext)UnitOfWork;}}}受保护的虚拟数据库集GetDbSet(),其中tenty:class{return Context.Set();}
因此,您需要为ICB创建自定义存储库,否则我无法创建该存储库。此方法是从该方法获得的。我有这个。Include()在其他情况下效果很好,也很好。我检查了我的模型,但由于某些原因,只有在ICBs中不起作用。
IQueryable icb = db.ICB.Include("ICBResources");