Here's my problem: I have a class that have 2 list properties of the same class type (but with some different restriction as on how to be filled), let's say:
public class Team { [Key] public int IDTeam { get; set; } public string TeamName { get; set; } public List<Programmer> Members { get; set; } public List<Programmer> Leaders { get; set; } public LoadLists(MyProjectDBContext db) { this.Members = db.Programmers.Where(p => p.IDTeam = this.IDTeam && (p.Experience == "" || p.Experience == null)).ToList(); this.Leaders = db.Programmers.Where(p => p.IDTeam = this.IDTeam && (p.Experience != null && p.Experience != "")).ToList(); } } public class Programmer { [Key] public int IDProgrammer { get; set; } [ForeignKey("Team")] public int IDTeam { get; set; } public virtual Team Team { get; set; } public string Name { get; set; } public string Experience { get; set; } } At some point, I need to take a list of Teams, with it's members and leaders, and for this I would assume something like:
return db.Teams .Include(m => m.Members.Where(p => p.Experience == "" || p.Experience == null) .Include(l => l.Leaders.Where(p => p.Experience != null && p.Experience != "") .OrderBy(t => t.TeamName) .ToList(); And, of course, in this case I would be assuming it wrong (cause it's not working at all). Any ideas on how to achieve that?
EDIT: To clarify a bit more, the 2 list properties of the team class should be filled according to:
1 - Members attribute - Should include all related proggramers with no experience (proggramer.Experience == null or "");
2 - Leaders attribute - Should include all related proggramers with any experience (programmer.Experiente != null nor "");
EDIT 2: Here's the MyProjectDbContext declaration:
public class MyProjectDBContext : DbContext { public DbSet<Team> Teams { get; set; } public DbSet<Programmer> Programmers { get; set; } }
db.Team(orDataContext.Tablefor that matter) even expose the.Includemethod? I can't seem to find it in my project nor in any official MSDN references. Maybe you could tryInsertOnSubmit / InsertAllOnSubmitorAttach / AttachAll.Includeis exposed by theDbSetclass. msdn.microsoft.com/en-us/library/…