c# - Entity Framework6 Code First Many To Many select always null -


After

I have established many relationships for many relationships that have been in my context;

  Protected Override Zero OnModelCreating (DbModelBuilder modelBuilder) {modelBuilder.Entity & LT; Module & gt; () HasMany (M => m.Questions) .WithMany () .map (q = & gt; {.T.TTTable ("Modules_And_Questions"); Q.MapLeftKey ("ModuleId"); q.MapRightKey ("QuestionId ");}); Base.OnModelCreating (modelBuilder); } Public Virtual DBset & lt; Module & gt; Module {receive; Set; } Public Virtual DbSet & lt; Question & gt; Question {Get; Set; }  

executed

  _context.modules.Where (m => m.ModuleId == 3);  

will return me to the appropriate module, but the question element is zero. (Checking this in the database shows that there are 40 questions for module 3).

A breakpoint indicates that OnModelCreating is getting hit. However, if it helps, I have seen that the wrong spelling model is not the reason of an error in the quote within the builder, so I doubt that I am speaking / installing this correctly.

So why the question is null, when it should include a list of 40 questions elements?

Text after "div class =" itemprop = "text">

This does not happen on your own. You must tell the EF that you include to load the query using :

  _context.modules.Include (M = & Gt; Metering Questions). Where (M => m.ModuleId == 3);  

If the Module.Questions property is marked as virtual (see example example of cuff), then it also works should do. As soon as you reach the Module.Questions property, such as questions will load. However, this will be a second database query, while using the include questions will be asked in combination with the module in a single database request.


Comments