I have two classes:
public class CarModel
{
public virtual int Id { get; set; }
public virtual string model_name { get; set; }
}
The issue here is in a doubled column mapping:
<property name="model" />
<many-to-one name="Modelis" column="model"
cascade="none" class="web_nt.Models.Class.CarModel" lazy="false" />
Both properties (valueType and Reference) are targeting same column. Which is possible but not for Write operations. We have to make one of them readonly using insert="false"
and update="false"
<property name="model" insert="false" update="false" />
<many-to-one name="Modelis" column="model"
cascade="none" class="web_nt.Models.Class.CarModel" lazy="false" />
So, now we do have access to both properties, mapped to same column, but the INSERT, UPDATE will target that column only once. Because that was the original issue here: ...ndex was out of range. Must be non-negative and less than the size of the collection...
Also check the similar issue: https://stackoverflow.com/a/24248912/1679310