【问题标题】:Error is coming while saving data with many to one mapping in nhibernate在 nhibernate 中使用多对一映射保存数据时出错
【发布时间】:2014-05-15 13:25:26
【问题描述】:

有两个表 DocumentType 和 EmployeeDocumentType。 EmployeeDocumentType w.r.t DocumentType 中有多行。

我需要在 EmployeeDocumentType 中使用多对一映射。我正在使用以下语法:

<many-to-one name="DocumentType" column="DocumentTypeId" class="DocumentType" />

EmployeeDocumentType 对象中的数据正确,但是当我将详细信息保存到 EmployeeDocumentType 时,它​​给出了错误,

此 SqlParameterCollection 的索引 14 无效,Count=14。

可能是什么问题。

【问题讨论】:

    标签: nhibernate nhibernate-mapping many-to-one


    【解决方案1】:

    这个问题(几乎可以肯定)doubled 映射有关。

    检查您的映射文件以查找可以使用 column="DocumentTypeId" 的其他位置
    (或通过某些默认约定为 name="DocumentTypeId"

    <!-- example of doubled mapping could be Int property representing the Int column -->
    <property    name="DocumentTypeId" column="DocumentTypeId" /> 
    <many-to-one name="DocumentType"   column="DocumentTypeId" class="DocumentType" />
    

    这里的解决方法很简单,其中一个必须标记为只读

    <property    name="DocumentTypeId" column="DocumentTypeId"
                                                           insert="false" update="false"/> 
    <many-to-one name="DocumentType"   column="DocumentTypeId" class="DocumentType" />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多