我看到這個How to include a child object's child object in Entity Framework 5如何包括子對象的子對象的實體框架5不工作
不過,我使用MVC 5和似乎並不奏效。
我有一個典型的比賽,遊戲,團隊結構,並試圖包括隊伍,當我查詢比賽。
我試圖運行
db.Tournaments.Include(t => t.Games.Select(g => g.Team1)).ToList();
但是TEAM1是回來了空。這裏是我的課程:
public class Tournament
{
public int TournamentId { get; set; }
public string Name { get; set; }
public virtual List<Game> Games { get; set; }
public virtual List<Standing> Standings { get; set; }
}
public class Game
{
public int GameId { get; set; }
public Location Location { get; set; }
public int LocationId { get; set; }
public virtual Team Team1 { get; set; }
public int Team1Id { get; set; }
public virtual Team Team2 { get; set; }
public int Team2Id { get; set; }
public int Team1Score { get; set; }
public int Team2Score { get; set; }
public DateTime Time { get; set; }
public Tournament Tournament { get; set; }
public int TournamentId { get; set; }
}
public class Team
{
public int TeamId { get; set; }
public string Name { get; set; }
public string Coach { get; set; }
}
有沒有人有任何建議?