• NHibernate Invalid index N for this SqlParameterCollection with Count=N Exception 简易处理


    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>

    当我插入数据的时候会报如下错误 :

    当我在插入数据的时候会报如下错误 :

    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行做测试.

    这里只启一个开头的作用, 具体的错误,根据自己的实际情况来解决.

  • 相关阅读:
    OpenGL中FrameBuffer使用
    每天进步一点点>结构化异常处理(SEH)
    js操作cookies
    [转]高性能网站优化与系统架构
    正则-匹配超链接地址及内容
    在c#.net中操作XML
    ActionScript 3 step by step (6) 元标记
    Facebook CEO:终极目标并非出售或上市
    ActionScript 3 step by step (3) 事件处理
    ActionScript 3 step by step (2) 使用Trace()跟踪输出
  • 原文地址:https://www.cnblogs.com/feinian/p/1657311.html
Copyright © 2020-2023  润新知