NHibernate的映射索引超出范围 [英] NHibernate mapping index out of range
问题描述
我有两个类:
public class CarModel
{
public virtual int Id { get; set; }
public virtual string model_name { get; set; }
}
和
public class Transport
{
public virtual int Id { get; set; }
public virtual string lic_plate { get; set; }
public virtual int model { get; set; }
public virtual string odometer { get; set; }
public virtual string moto_val { get; set; }
public virtual Class.CarModel Modelis { get; set; }
}
和映射:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="true" assembly="web_nt" namespace="web_nt.Models">
<class name="Transport" table="transport" dynamic-update="true" lazy="false">
<id name="Id" column="Id" type="int">
<generator class="native" />
</id>
<property name="lic_plate" />
<property name="model" />
<property name="odometer" />
<property name="moto_val" />
<many-to-one name="Modelis" column="model" cascade="none" class="web_nt.Models.Class.CarModel" lazy="false" />
</class>
<class name="web_nt.Models.Class.CarModel" table="car_model">
<id name="Id" column="id" type="int">
<generator class="native" />
</id>
<property name="model_name" />
</class>
</hibernate-mapping>
和我得到的例外,当我尝试值发送给数据库(鉴于它完美):+ $异常{索引超出范围必须为非负值并小于集合的大小\\ r \\ n参数名称索引:} {System.Exception的} System.ArgumentOutOfRangeException
And I get exception when I try to send values to database(In view it works perfectly): + $exception {"Index was out of range. Must be non-negative and less than the size of the collection.\r\nParameter name: index"} System.Exception {System.ArgumentOutOfRangeException}
和我找不到什么可能是错在这里?
And I can't find what might be wrong here?
推荐答案
这里的问题是在一倍列映射:
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" />
这两个属性(VALUETYPE和参考)瞄准同一列。这是可能的,但不是写操作。我们必须让他们中的一个的只读是插入=FALSE
和更新=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" />
所以,现在我们也有机会获得这两个属性,映射到同一列,但是INSERT,UPDATE将针对该列只有一次。因为这是原来的问题在这里: ... ndex超出范围。必须大于集合的大小非负和更少... 的
另外,还要检查类似的问题:<一href=\"http://stackoverflow.com/a/24248912/1679310\">http://stackoverflow.com/a/24248912/1679310
Also check the similar issue: http://stackoverflow.com/a/24248912/1679310
这篇关于NHibernate的映射索引超出范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!