title: Can't add item with existing Id to the database
body: <p>I have a comparsion list. I can add a product to it, but when I try to add another product to this list, I'm getting error:</p>
  
  <p><em>The instance of entity type 'ProductToCompare' cannot be tracked because another instance with the key value '{ProductComparsionId: 13}' is already being tracked</em></p>
  
  <p>What I am doing wrong?</p>
  
  <p><a href="https://i.stack.imgur.com/YdY4a.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YdY4a.jpg" alt="enter image description here"></a></p>
  
  <p><strong>Models:</strong></p>
  
  <pre><code>public class ProductComparsion
  {
      public int Id { get; set; }
      public int? UserId { get; set; }
      public Guid SessionId { get; set; }
      public int CategoryId { get; set; }
      public DateTime Created { get; set; }
      public ICollection&lt;ProductToCompare&gt; ProductsToCompare { get; set; }
  }
  
  public class ProductToCompare
  {
      public int ProductComparsionId { get; set; }
      public ProductComparsion ProductComparsion { get; set; }
      public int ProductId { get; set; }
      public Product Product { get; set; }        
  }
  </code></pre>
  
  <p><strong>EF:</strong></p>
  
  <pre><code>public class AppDbContext : CmsDbContextBase, ILocalizedDbContext
  {
      public DbSet&lt;ProductComparsion&gt; ProductsComparsion { get; set; }
      public DbSet&lt;ProductToCompare&gt; ProductsToCompare { get; set; }
  }
  
  public class AppDbContextModelProvider : ModelProvider
  {
      protected override void OnModelCreating(DbContext dbContext, ModelBuilder modelBuilder)
      {
          modelBuilder.Entity&lt;ProductComparsion&gt;(typeBuiler =&gt;
          {
              typeBuiler.ToTable(nameof(AppDbContext.ProductsComparsion));
              typeBuiler.HasKey(z =&gt; z.Id);
          });
  
          modelBuilder.Entity&lt;ProductToCompare&gt;(typeBuilder =&gt;
          {
              typeBuilder.ToTable(nameof(AppDbContext.ProductsToCompare));
              typeBuilder.HasKey(z =&gt; z.ProductComparsionId);
              typeBuilder.HasOne(z =&gt; z.ProductComparsion).WithMany(z =&gt; z.ProductsToCompare).HasForeignKey(z =&gt; z.ProductComparsionId);
          });
      }
  }
  </code></pre>
  
  <p><strong>Adding data to DB:</strong></p>
  
  <pre><code>    public async Task&lt;ProductComparsionVM&gt; AddProductToComparsionList(List&lt;int&gt; productIds, int listId = 0)
      {
          var comparsionList = await _dbContext.ProductsComparsion
              .AsNoTracking()
              .Include(z =&gt; z.ProductsToCompare)
              .FirstOrDefaultAsync(z =&gt; z.Id.Equals(listId));
  
          Guid sessionId = default;
          Guid.TryParse(_httpContextAccessor.HttpContext.Session.Id, out sessionId);
  
          var products = _dbContext.Products.Include(z =&gt; z.ProductCategories);
  
          foreach (var productId in productIds)
          {                
              comparsionList.ProductsToCompare.Add(new ProductToCompare { ProductId = productId });
              comparsionList.SessionId = sessionId;
  
              var user = _userManager.GetUserAsync(_httpContextAccessor.HttpContext.User).GetAwaiter().GetResult();
              comparsionList.UserId = user == null ? null : (int?)user.Id;
          }                          
  
          await _dbContext.AddAsync(comparsionList);
          await _dbContext.SaveChangesAsync();
          return null;
      }
  </code></pre>
  
  <p><strong>Edit 1</strong></p>
  
  <p><a href="https://i.stack.imgur.com/FqmOI.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FqmOI.jpg" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/4BQbO.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4BQbO.jpg" alt="enter image description here"></a></p>