title: Adding collection of owned objects
body: <p>I've got a domain model with collection of owned types. When I try to add more than one object in the ownedtyped collection? I get an exception:</p>
  
  <blockquote>
    <p><strong>System.InvalidOperationException</strong>: 'The instance of entity type 'ChildItem' cannot be tracked because another 
    instance with the key value '{NameId: -2147482647, Id: 0}' is already being 
    tracked. When replacing owned entities modify the properties without changing 
    the instance or detach the previous owned entity entry first.'</p>
  </blockquote>
  
  <p>How can it be solved?</p>
  
  <p><strong>UPDATED</strong></p>
  
  <p><strong>My domain classes:</strong></p>
  
  <pre><code>public class Parent
      {
          public int Id { get; set; }
          public Child Name { get; set; }
          public Child ShortName { get; set; }
      }
  
      public class Child
      {
          public List&lt;ChildItem&gt; Items { get; set; }
      }
  
      public class ChildItem
      {
          public string Text { get; set; }
          public string Language { get; set; }
      }
  </code></pre>
  
  <p><strong>My DbContext:</strong></p>
  
  <pre><code>public class ApplicationContext : DbContext
      {
          protected override void OnModelCreating(ModelBuilder modelBuilder)
          {
              modelBuilder.Entity&lt;Parent&gt;()
                  .OwnsOne(c =&gt; c.Name, d =&gt;
                  {
                      d.OwnsMany(c =&gt; c.Items, a =&gt;
                      {
                          a.HasForeignKey("NameId");
                          a.Property&lt;int&gt;("Id");
                          a.HasKey("NameId", "Id");
                          a.ToTable("ParentNameItems");
                      })
                      .ToTable("ParentName");
                  })
                  .ToTable("Parent");
  
                  modelBuilder.Entity&lt;Parent&gt;()
                  .OwnsOne(c =&gt; c.ShortName, d =&gt;
                  {
                      d.OwnsMany(c =&gt; c.Items, a =&gt;
                      {
                          a.HasForeignKey("NameId");
                          a.Property&lt;int&gt;("Id");
                          a.HasKey("NameId", "Id");
                          a.ToTable("ParentShortNameItems");
                      })
                      .ToTable("ParentShortName");
                  })
                  .ToTable("Parent");
          }
      }
  </code></pre>
  
  <p><strong>Usage:</strong></p>
  
  <pre><code>static void Main(string[] args)
          {
              var context = new ApplicationContext();
  
              var parent = new Parent()
              {
                  Name = new Child()
                  {
                      Items = new List&lt;ChildItem&gt;()
                      {
                          new ChildItem() { Text = "First value", Language = "en-en"},
                          new ChildItem() { Text = "Second value", Language = "en-en"}
                      }
                  },
                  ShortName = new Child()
                  {
                      Items = new List&lt;ChildItem&gt;()
                      {
                          new ChildItem() { Text = "First short value", Language = "en-en"},
                          new ChildItem() { Text = "Second short value", Language = "en-en"}
                      }
                  }
              };
  
              context.Set&lt;Parent&gt;().Add(parent);
  
              context.SaveChanges();
          }
  </code></pre>