Entity Framework Core 7: Handling Composite Keys with Conflicting Entity State During Updates
I'm deploying to production and I've tried everything I can think of but I'm working with an scenario when trying to update an entity with a composite key using Entity Framework Core 7. I have a `Order` entity that consists of `OrderId` and `ProductId` as a composite key. When I attempt to update an existing order, I receive the behavior: `The instance of entity type 'Order' want to be tracked because another instance with the same key value for {'OrderId', 'ProductId'} is already being tracked.` I have tried detaching the existing entity before updating, but it doesn't seem to resolve the scenario. My current code looks like this: ```csharp using (var context = new MyDbContext()) { var existingOrder = context.Orders.Find(orderId, productId); if (existingOrder != null) { context.Entry(existingOrder).CurrentValues.SetValues(updatedOrder); context.SaveChanges(); } else { // Handle order not found } } ``` The `updatedOrder` is a new instance of `Order` with the same composite key. I also tried using `Attach()` method before setting the values, but that led to another behavior: `The entity type 'Order' is not configured for the specified key properties.` I'm not sure how to correctly update the existing entity without running into tracking issues. Is there a recommended pattern or best practice for handling updates with composite keys in EF Core 7? Any help would be appreciated! I'm on Ubuntu 22.04 using the latest version of Csharp. Cheers for any assistance! This is for a service running on Windows 11. Any ideas what could be causing this?