title: How to associate entities during seed with Entity Framework
body: <p>I have these classes:</p>
  
  <pre><code>[Serializable]
  public class Module
  {
          [Key]
          public int Id { get; set; }
          public string ModuleName { get; set; }
          public string FontAwesomeClass { get; set; }
  }
  
  [Serializable]
  public class ModulosPorUsuario
  {
          public string Email { get; set; }
          public List&lt;Module&gt; Modules{ get; set; }
  }
  </code></pre>
  
  <p>And I need to seed like this:</p>
  
  <pre><code>#region Seed Modules
      context.Modulos.Add(new Module() { Id = 1, ModuleName = "Contabilidad", FontAwesomeClass = "fa-ambulance" });
      context.Modulos.Add(new Module() { Id = 2, ModuleName = "Recursos Humanos", FontAwesomeClass = "fa-heartbeat" });
      context.Modulos.Add(new Module() { Id = 3, ModuleName = "Inventario", FontAwesomeClass = "fa-anchor" });
      context.Modulos.Add(new Module() { Id = 3, ModuleName = "Produccion", FontAwesomeClass = "fa-binoculars" });
      context.Modulos.Add(new Module() { Id = 3, ModuleName = "Ventas", FontAwesomeClass = "fa-coffee" });
      context.Modulos.Add(new Module() { Id = 3, ModuleName = "Compras", FontAwesomeClass = "fa-calendar-o" });
      context.Modulos.Add(new Module() { Id = 3, ModuleName = "Cotizaciones", FontAwesomeClass = "fa-building" });
      #endregion
  </code></pre>
  
  <p>However my question is how can I associate a list of modules that were previously seeded??</p>
  
  <pre><code>    #region Seed ModulosPor Usuario
      context.ModulosPorUsuario.Add(new ModulosPorUsuario()
      {
          Email = "companyadmin@xx.onmicrosoft.com",
          Modules = ???
      });
  
      #endregion
  </code></pre>
  
  <p><strong>Update 1:</strong></p>
  
  <p>When I check the tables created for me this doesnt look right.  A module is an entity by its own, and ModulesPeruser should be a relationship between email and many different modules.
  However on the Module table it created a foreign key to ModulesPerUser.</p>
  
  <p>What is wrong with my design?
  <a href="http://screencast.com/t/Z0u2950zm" rel="nofollow">http://screencast.com/t/Z0u2950zm</a></p>