EF 6 및 코드 우선을 사용하고 있습니다. 그러나 데이터베이스에서 ICB 목록을 수집하려고 할 때 어떤 이유로 (예를 들어 Station) 종속성이 반환되지 않습니다. 채워진 객체 (icb.station), 스테이션 ID 만. 나는이 관계가있다.includes() 함수가 작동하지 않습니다.
공용 클래스 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; }
}
내가 가득 모든 회원을 가지고해야합니까? 그들은 신분증만을 제공하고 있습니다. .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();
}
}
그것은 내 dbContext의 '보호 TargetDbContext 컨텍스트 { GET {리턴 (TargetDbContext)의 UnitOfWork; 보호} } 가상 DbSet GetDbSet () TEntity : 클래스 { 반환 Context.Set (); }' –
CidaoPapito
ICB 용 사용자 정의 리포지토리를 만들어야합니다. 그렇지 않으면 작동하지 않습니다. – sylwester
만들었습니다. 이 메소드는 GetAllICBs를 사용합니다. 나는 이것을 가지고있다. 포함()은 다른 상황에서 잘 작동하고 잘 작동한다. 내 모델을 확인했지만 ICB에서만 작동하는 것은 아닙니다. – CidaoPapito