I have a Many to Many relationship set up such that in my context I have;
protected override void OnModelCreating(DbModelBuilder modelBuilder){ modelBuilder.Entity<Module>().HasMany(m => m.Questions).WithMany() .Map(q => { q.ToTable("Modules_And_Questions"); q.MapLeftKey("ModuleId"); q.MapRightKey("QuestionId"); }); base.OnModelCreating(modelBuilder); } public virtual DbSet<Module> Modules { get; set; } public virtual DbSet<Question> Questions { get; set; } executing
_context.Modules.Where(m => m.ModuleId == 3); will return me the appropriate module, but the questions element is null. (Checking this in the database shows that there are 40 questions for module 3.)
A breakpoint shows that OnModelCreating is being hit. Though if it helps, I have noticed that mis-spelling any of the elements in quotes within the model builder does not cause an error, so I have my doubts that I am calling / setting this up correctly.
So why is Questions Null, when it should contain a list of 40 Question elements?