title: EF Core - 2 Entities, each with a reference to another lookup Entity. On Add - IOE - cannot be tracked because another instance with the key value
body: <p>We're using EF Core 3.1</p>
  
  <p>We have 2 Entities - <code>item</code> and <code>batch</code>. Each have a reference to <code>currency</code>. When we add both an item and a batch, each with a  reference to a loaded (and tracked) <code>currency</code> EF Core spits out the following <code>System.InvalidOperationException</code>:</p>
  
  <pre><code>The instance of entity type 'Currency' cannot be tracked because another instance with the key value '{Id: 103}' is already being tracked. When attaching existing entities, ensure that only one entity instance with a given key value is attached.
  </code></pre>
  
  <p>We're not doing anything too irregular:</p>
  
  <pre><code>                var currency = _context.Set&lt;Currency&gt;.SingleOrDefault(currencyId);
  
                  var item = new Item(currency);
                  var batch = Batch.Create(currency, new[] { item });
                  _context.Set&lt;Batch&gt;.Add(batch);
                  item.Batch = batch;                        
                  _context.Set&lt;Item&gt;.Add(instruction);
  </code></pre>
  
  <p>And our maps have fks etc <code>ItemMap</code>:</p>
  
  <pre><code>            modelBuilder
                  .HasOne(i =&gt; i.Currency)
                  .WithMany()
                  .IsRequired();
  
              modelBuilder
                  .HasOne(i =&gt; i.Batch)
                  .WithMany();
  </code></pre>
  
  <p>and <code>BatchMap</code>:</p>
  
  <pre><code>            modelBuilder
                  .HasOne(i =&gt; i.Currency)
                  .WithMany()
                  .IsRequired();
  </code></pre>
  
  <p>and <code>CurrencyMap</code>:</p>
  
  <pre><code>            modelBuilder
                  .ToTable("Currency")
                  .HasKey(cur =&gt; cur.Id);
  
              modelBuilder
                  .HasData(new Currency(103));
  </code></pre>
  
  <p>I wonder if anyone can point out my stupidity or at least explain where I may be going wrong?</p>