title: Seed entity with owned property
body: <p>I am trying to seed an user entity in my database. The <code>User</code> entity has an owend property <code>EmailPermissions</code>.</p>
  
  <p>When I run the command</p>
  
  <blockquote>
    <p>dotnet ef migrations add Initial;</p>
  </blockquote>
  
  <p>I get the error </p>
  
  <blockquote>
    <p>The seed entity for entity type 'User' cannot be added because it has the navigation 'EmailPermissions' set. To seed relationships you need to add the related entity seed to 'EmailPermissions' and specify the foreign key values {'UserId'}.</p>
  </blockquote>
  
  <p>but since <code>EmailPermissions</code> is an owned entity I didn't give it an explicit <code>UserId</code> property, meaning I can't seed it separately in the database.</p>
  
  <p>the entity</p>
  
  <pre><code>public sealed class User : IdentityUser
  {
      public User()
      {
          EmailPermissions = new EmailPermissions();
      }
  
      /* [..] */
  
      public string TemporaryEmailBeforeChange { get; set; }
      public bool IsEmailAwaitingUpdate { get; set; }
      public EmailPermissions EmailPermissions { get; set; }
      public ICollection&lt;Registeration&gt; Registerations { get; set; }
  
      /* [..] */
  
  }
  
  [Owned]
  public class EmailPermissions
  {
      /* [..] */
  
      public bool Newsletter { get; set; }
      public bool PromotionalOffers { get; set; }
      public bool PrestationReminders { get; set; }
      public bool PrestationOffers { get; set; }
  }
  </code></pre>
  
  <p>The seeding call</p>
  
  <pre><code>private void SeedUser(ModelBuilder builder)
  {
      builder.Entity&lt;User&gt;().HasData(
          new User
          {
              Id = "37846734-172e-4149-8cec-6f43d1eb3f60",
              Email = "foo@foo.foo",
              UserName = "foo@foo.foo",
              PasswordHash = "AQAAAAEAACcQAAAAEIytBES+jqKH9jfuY3wzKyduDZruyHMGE6P+ODe1pSKM7BuGjd3AIe6RGRHrXidRsg==",
              SecurityStamp = "WR6VVAGISJYOZQ3W7LGB53EGNXCWB5MS",
              ConcurrencyStamp = "c470e139-5880-4002-8844-ed72ba7b4b80",
              EmailConfirmed = true
          });
  }   
  </code></pre>
  
  <p>If I remove the instantiation of the <code>EmailPermissions</code> property from the constructor I get the following error instead</p>
  
  <blockquote>
    <p>The entity of type 'User' is sharing the table 'AspNetUsers' with entities of type 'EmailPermissions', but there is no entity of this type with the same key value that has been marked as 'Added'.</p>
  </blockquote>
  
  <p>How can I seed a user via the <code>.HasData</code> method when it has an owned property ?</p>