title: Entity Framework: relate identity 2 user to product model
body: <p>I'm using Web API 2 and Entity Framework 6 and Identity 2</p>
  
  <p>I have product model which relates to an <code>ApplicationUser</code> model, where I create <code>Product</code>, I get an error:</p>
  
  <blockquote>
    <p>Additional information: An entity object cannot be referenced by multiple instances of IEntityChangeTracker.</p>
  </blockquote>
  
  <p>My model:</p>
  
  <pre><code>public class Product {
      public int id { get; set; }
      public string url { get; set; }
      public string name {get;set}
      public ApplicationUser user { get; set; }
  }
  </code></pre>
  
  <p>My create code:</p>
  
  <pre><code>public IHttpActionResult PostProduct(Product product) {
      ApplicationUserManager userManager = new ApplicationUserManager(new UserStore&lt;ApplicationUser&gt;(new ApplicationDbContext()));
  
      product.user = userManager.FindById(User.Identity.GetUserId());
  
      if (!ModelState.IsValid) {
          return BadRequest(ModelState);
      }
  
      db.Products.Add(product);
      db.SaveChanges();
  
      return CreatedAtRoute("DefaultApi", new { id = product.id }, product);
  }
  </code></pre>