I have a db-first Entity Framework application and the following associations:
Customer * <-> 1 Country
Machine * <-> 1 Customer
Everything is fine until now. Now here is the problem:
I have another class Condition associated with a machine as well as with a customer:
Condition * <-> 1 Customer
Condition * <-> 1 Machine
In one special entity Condition.Machine.Customer.Country is the same entity as Condition.Customer.Country and i get an InvalidOperationException with the message
An object with the same key already exists in the ObjectStateManager
This exception appears when i call
db.Entry(condition).State = EntityState.Modified;
Also the Country Entites are unchanged i get this Exception.
How can i now store the Condition Entity?