In EF6, I load my airport from the DB:
var existingAirport = db.Airports.SingleOrDefault(a => a.ID == airportID)
//airport is loaded, it has a countryID and virtual Country object
I perform some logic which makes some modifications to alter the relationship, changing both the country object and FK ID:
//it's a bit more complex, but simplified:
existingAirport.Country = //the someOtherCountryObject
existingAirport.CountyID = //the someOtherCountryObject.ID
I save the change (which should assign the airport the new country)
db.SaveChanges();
The problem is EF decides to null the relationship in both the DB and memory (existingAirport.Country and existingAirport.CountyID are both now null). The airport is now associated with neither the new or old country.
Can anyone think of a reason EF is doing this? The new FK points to a valid country.