NHibernate mapping index out of range

后端 未结 1 696
礼貌的吻别
礼貌的吻别 2021-01-21 20:28

I have two classes:

 public class CarModel
    {
        public virtual int Id { get; set; }
        public virtual string model_name { get; set; }
    }


        
相关标签:
1条回答
  • 2021-01-21 20:35

    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

    0 讨论(0)
提交回复
热议问题