Let's say you have the following scheme: 
If you want to edit CurrentLocationId in Person, you also need to edit the CurrentLocation object embedded in the Person object. EF will automatically populate the CurrentLocation object, because CurrentLocationId has a foreign key in the CurrentLocation table. When you edit CurrentLocationId without updating also the CurrentLocation object, they become out of sync. This is what throws an exception in this case.
Suppose you need to update the Person object CurrentLocationId. We assume that you have preloaded Person data and Location data.
public class DbData { List<Person> PersonList; List<Location> LocationList; public DbData() { using (var context = new MyContext()) { PersonList = context.Persons.ToList(); LocationList = context.Locations.ToList(); } } public void UpdatePersonLocation(Person person, int newLocationId) { using (var context = new MyContext()) { var location = LocationList.Where(l=>l.id==newLocationId).Single();
Migit source share