I have a mapping like this
<class name="UserFileSummary" table="UserFile" lazy="false">
<id name="FileId" column="UserFileId" type="int">
<generator class="identity" />
</id>...
and a property in the c# object like this
public long FileId { get; set; }
What I don’t understand is why when I get an instance using
var myFile = session.Get<UserFileSummary>(id)
change a field value and then save it like this
myFile.myProperty = newValue
session.Save(myFile)
I get an error saying the the Id have been altered from 1 to 1. There are some posts around about this, but this is a simple int column (identity 1, 1). I must have made some basic error, please can anyone help out. Thanks
I’ve added this bit as an edit as the question turns out to be a non question
The FileId property is type long, and the mapping is type int, that is why altered from 1 to 1 is a problem.
Please give me some feedback if you want me to delete this question, thanks everyone 🙂
The error in my case was due to the data type being a long (int64) in the database and being mapped to an int (int32) in the mapping. This meant that the real value changed whenever the object was saved, thus breaking the identifier. Thanks to everyone who helped out.