包括 matchparticipants 不起作用。我调试时它总是说空。但是当我将 GroupBy 放在评论中时,它工作正常。我正在使用代码优先的实体框架 4.3.1。
实体:
public class Match
{
[ScaffoldColumn(false)]
public int MatchId { get; set; }
[Required(ErrorMessage = "Matchtype is a required field")]
public int Scheme { get; set; }
[Required]
[DefaultValue(false)]
public bool Finished { get; set; }
public int Round { get; set; }
// Relations
[Required]
public Category Category { get; set; }
public Official Official { get; set; }
public Slot Slot { get; set; }
public ICollection<MatchParticipant> MatchParticipants { get; set; }
}
public class MatchParticipant
{
[ScaffoldColumn(false)]
public int MatchParticipantId { get; set; }
public int Points { get; set; }
public int Goals { get; set; }
[Required]
public Match Match { get; set; }
[Required]
public Team Team { get; set; }
}
public class Team
{
[ScaffoldColumn(false)]
public int TeamId { get; set; }
[Required(ErrorMessage="Name is a required field")]
public string Name { get; set; }
[Required(ErrorMessage="Number of players is a required field")]
public int NumberOfPlayers { get; set; }
[Required(ErrorMessage="Coach is a required field")]
public string Coach { get; set; }
[Required(ErrorMessage="Phone is a required field")]
public string Phone { get; set; }
public string CellPhone { get; set; }
public string Fax { get; set; }
[Required(ErrorMessage="Email is a required field")]
public string Email { get; set; }
[Required(ErrorMessage="Address is a required field")]
public Address Address { get; set; }
public Pool Pool { get; set; }
[Required(ErrorMessage = "Category is a required field")]
public Category Category { get; set; }
public ICollection<MatchParticipant> matchParticipants { get; set; }
}
var matches =
context.matches
.Include("Official")
.Include("Slot")
.Include("MatchParticipants.Team")
.Include("Category.Tournament")
.Where(m => m.Category.Tournament.TournamentId == tournamentId)
.GroupBy(m => m.Category);
如何使包含工作?