Demo Mapping Config:
1 <class name="BaseTable" table="BaseTable">
2 <id name="BaseId">
3 <generator class="native"/>
4 </id>
5 <!--<discriminator column="SubType" type="String"/>-->
6 <property name="Name" column="Name" type="String" />
7 <property name="SubType" column="SubType" type="String" />
8 <property name="BaseIrType" column="IrType" type="String"/>
9
10 <any name="SubObj" meta-type="string" id-type="Int32" cascade="all">
11 <meta-value value="People" class="Person"/>
12 <meta-value value="Company" class="Company"/>
13 <column name="SubType" />
14 <column name="SubId"/>
15 </any>
16 </class>
2 <id name="BaseId">
3 <generator class="native"/>
4 </id>
5 <!--<discriminator column="SubType" type="String"/>-->
6 <property name="Name" column="Name" type="String" />
7 <property name="SubType" column="SubType" type="String" />
8 <property name="BaseIrType" column="IrType" type="String"/>
9
10 <any name="SubObj" meta-type="string" id-type="Int32" cascade="all">
11 <meta-value value="People" class="Person"/>
12 <meta-value value="Company" class="Company"/>
13 <column name="SubType" />
14 <column name="SubId"/>
15 </any>
16 </class>
当我插入数据的时候会报如下错误 :
当我在插入数据的时候会报如下错误 :
NHibernate: INSERT INTO People (FirstName, IrType) VALUES (@p0, @p1); select SCOPE_IDENTITY();@p0 = 'Cheng', @p1 = '0000AA'
TestCase 'NHDemo.Test.NHibernateSampleFixture.GetCustomerByIdTest'
failed: System.IndexOutOfRangeException : Invalid index 4 for this SqlParameterCollection with Count=4.
at System.Data.SqlClient.SqlParameterCollection.RangeCheck(Int32 index)
at System.Data.SqlClient.SqlParameterCollection.GetParameter(Int32 index)
at System.Data.Common.DbParameterCollection.System.Collections.IList.get_Item(Int32 index)
此处异常显示: N = 4, 那就是配置文件的第4行有问题, 可以简单的先注释第4行做测试.
这里只启一个开头的作用, 具体的错误,根据自己的实际情况来解决.