I have a small ASP.NET MVC application with the following entity objects:
Person
- Personid
- Name (string)
- FirstName (string)
- Country (Country)
The country
I can add and remove an object that works fine. I can also update the name, the name. But how can I renew the property of a country by another country.
I've tried
p.Country = (from c in db.Country
where c.CountryId == countryId
select c).First();
but this throws an exception {"An object with the same key already exists in the ObjectStateManager. ObjectStateManager cannot track multiple objects with the same key." } "
even before I call SaveChanges in the datacontext.
Can someone explain how I can update this property?
Regards, Dieter