title: Why is not Entity Framework initializing my navigation collections?
body: <p>I'm creating an ASP.NET MVC4 tournament administration system which as a containing class <code>Tournament</code> with a collection of <code>Round</code> objects. I'm new to EF Code First, but I've understood that EF is  <a href="https://stackoverflow.com/a/4069727/507339">supposed to initialize</a> my collection objects with observed proxy classes upon instantiation, as long as I've declared them as virtual. Why are they null when I try to add elements to them from the ASP.NET controller in the code below?</p>
  
  <pre><code>public class Tournament
  {
      public int Id { get; set; }
      [Required]
      public String Name { get; set; }
      public virtual ICollection&lt;Contestant&gt; Contestants { get; set; }
      public virtual ICollection&lt;Round&gt; Rounds { get; set; }  
  
      public void InitializeDefaults()
      {
          var round = new Round("Round 1");
          Rounds.Add(round); // Generates NullReferenceException when called from controller
      }
  }
  
  public class Round
  {
      public long Id { get; set; }
      public int MaxContestants { get; set; }
      public String Title { get; set; } 
      public Round() { }
      public Round(string title) : this()
      {
          Title = title;
      }
  }
  
  public class MainController {
      // (...)
      [HttpPost]
      public ActionResult CreateTournament(Tournament tournament)
      {
          var db = new DataContext(); 
          var dbTournament = db.Tournaments.Create();
          dbTournament.Name = tournament.Name;
          db.Tournaments.Add(dbTournament);
          dbTournament.InitializeDefaults();
          db.SaveChanges();
          return RedirectToRoute(new { action = "Main", tournamentId = dbTournament.Id });
      }
  }
  
  
  public class DataContext : DbContext
  {
      public IDbSet&lt;Tournament&gt; Tournaments { get; set; }
      public IDbSet&lt;Judge&gt; Judges { get; set; }
      public IDbSet&lt;Contestant&gt; Contestants { get; set; }
  }
  </code></pre>
  
  <p><strong>update</strong></p>
  
  <p>Reinitializing the dataContext after saving the entity, solves my problem. But in not the right way. Original question stands. </p>
  
  <p>Altered <code>CreateTournament</code>-method</p>
  
  <pre><code>[HttpPost]
  public ActionResult CreateTournament(Tournament tournament)
  {
      var db = App.ServiceLocator.GetDataBase();
      db.Tournaments.Add(tournament);
      db.SaveChanges();
      db.Dispose();
  
      // Reinitializing the datacontext
      db = App.ServiceLocator.GetDataBase();
      var dbTournament = db.GetTournament(tournament.Id);
      dbTournament.InitializeDefaults();
      db.SaveChanges();
      return RedirectToRoute(new { action = "Main", tournamentId = dbTournament.Id });
  }
  </code></pre>