I have a User object that has a Country object on it. I map this with a many-to-one tag in the User mapping file:
<many-to-one name="Country" column="CountryID" cascade="none"/>
How do I update a User's country?
At the moment my UI has a dropdown of countries and the ID of the new country is passed to the controller. The controller then sets the ID of the User's country from that value. So:
var user = session.Get<User>(userID);
user.Country.ID = Convert.ToInt32(Request.Form["Country_ID"]);
But when I call:
session.SaveOrUpdate(user);
I get an error saying that "identifier of an instance of Country was altered from 7 to 8". Presumably this is because the Country object is marked as dirty by NHibernate? I don't want to update the country object though, just the ID reference in the User. Is it possible to do it this way?
Thanks, Jon