bao gồm matchparticipants không hoạt động. Nó luôn luôn nói Null khi tôi gỡ lỗi. Nhưng khi tôi đặt GroupBy vào bình luận thì nó hoạt động tốt. Tôi đang sử dụng khung Entity 4.3.1 với mã đầu tiên.LINQ khi sử dụng GroupBy, Bao gồm không hoạt động
Đối tượng:
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);
Làm thế nào tôi có thể làm cho Bao gồm công việc?
Cảm ơn người đàn ông nó hoạt động tốt ngay bây giờ :) – Bart
Bất kỳ đề xuất nào khác về thời điểm bạn phải giữ loại đối tượng là IQueryable <>? –