【发布时间】:2014-05-23 21:54:23
【问题描述】:
我使用的是 EF 6 和 Code First,但由于某种原因,当我尝试从数据库中收集 ICB 列表时,依赖项(例如 Station)不会作为填充对象(icb.station)返回,只有电台 ID。我有这种关系。
公共类ICB {
public ICB()
{
ICBResources = new List<ICBResource>();
}
public int ICBId { get; set; }
public int LevelId { get; set; }
public virtual Station Station { get; set; }
public string Location { get; set; }
public DateTime TimeOfCall { get; set; }
public DateTime TimeStarted { get; set; }
public Staff IncidentCommander { get; set; }
public Staff OperationsCommander { get; set; }
public Staff SectorCommander { get; set; }
public Staff SectorCommander2 { get; set; }
public Staff CommandSupportOfficer { get; set; }
public Staff SafetyOfficer { get; set; }
public Staff CommunicationsOfficer { get; set; }
public Staff WaterOfficer { get; set; }
public Staff BAOfficer { get; set; }
public Staff HazmatOfficer { get; set; }
public virtual Company Company { 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();
}
}
【问题讨论】:
标签: c# entity-framework ef-code-first linq-to-entities