I tried to implement the Value Object pattern for EF Core 2.0: https://learn.microsoft.com/en-us/dotnet/standard/microservices-architecture/microservice-ddd-cqrs-patterns/implement-value-objects
According to the example of Microsoft I added following method to the Order Aggregate Root:
public void SetAddress(Address address)
{
Address = address;
}
So I call this method and save the changes:
orderToUpdate.SetAddress(address);
await _orderRepository.UnitOfWork.SaveEntitiesAsync();
But when I try to update it the following error is thrown:
InvalidOperationException: The instance of entity type ...; cannot be tracked because another instance with the same key value for ... is already being tracked. When replacing owned entities modify the properties without changing the instance or detach the previous owned entity entry first.
Was the Value Object pattern never intended for updating or am I doing something wrong?