title: EF Core Value Object Owned by many
body: <p>I use a value object to represent the Price</p>
  <pre><code>public record Price(decimal Amount, string Currency);
  </code></pre>
  <p>Then I have two entities with a price</p>
  <pre><code>public class Item 
  {
      public Price { get; private set; }
      // rest of properties
  }
  
  public class OrderPosition 
  {
      public Price { get; private set; }
      // rest
  }
  </code></pre>
  <p>In the DB I would like to have these two tables</p>
  <pre><code>Items
  | Id | Price_Amount | Price_Currency |
  
  
  OrderPositions
  | Id | Price_Amount | Price_Currency |
  
  </code></pre>
  <p>To achieve this i configured the Price to be an owned type of the item aswell as the order position:</p>
  <pre><code>public class ItemConfiguration : IEntityTypeConfiguration&lt;Item&gt;
  {
      public void Configure(EntityTypeBuilder&lt;Item&gt; builder)
      {
          builder.OwnsOne(i =&gt; i.Price);
      }
  }
  
  public class ItemConfiguration : IEntityTypeConfiguration&lt;OrderPosition&gt;
  {
      public void Configure(EntityTypeBuilder&lt;OrderPosition&gt; builder)
      {
          builder.OwnsOne(op =&gt; op.Price);
      }
  }
  </code></pre>
  <p>This works all fine but EF gives me a warning when I have the same price on an item aswell as on the order position:</p>
  <pre><code>[09:47:59 WRN] The same entity is being tracked as different entity types 'Item.Price#Price' and 'OrderPosition.Price#Price' with defining navigations. If a property value changes, it will result in two store changes, which might not be the desired outcome.
  </code></pre>
  <p>And I understand the exception fully, it is even documented as a by design restriction: <a href="https://docs.microsoft.com/en-us/ef/core/modeling/owned-entities#by-design-restrictions" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/ef/core/modeling/owned-entities#by-design-restrictions</a></p>
  <pre><code>Instances of owned entity types cannot be shared by multiple owners (this is a well-known scenario for value objects that cannot be implemented using owned entity types).
  </code></pre>
  <p>But how do you solve this issue? Do I need to make a derived class for ItemPrice and OrderPositionPrice with implicit conversions to each other? This would work but I think this is not the best solution.</p>