在nhibernate中使用多对一映射保存数据时出错
有两个表DocumentType和EmployeeDocumentType。EmployeeDocumentType w.r.t DocumentType中有多行 我需要在EmployeeDocumentType中使用多对一映射。我使用以下语法:在nhibernate中使用多对一映射保存数据时出错,nhibernate,nhibernate-mapping,many-to-one,Nhibernate,Nhibernate Mapping,Many To One,有两个表DocumentType和EmployeeDocumentType。EmployeeDocumentType w.r.t DocumentType中有多行 我需要在EmployeeDocumentType中使用多对一映射。我使用以下语法: <many-to-one name="DocumentType" column="DocumentTypeId" class="DocumentType" /> EmployeeDocumentType对象中的数据正确,但当我将详细信
<many-to-one name="DocumentType" column="DocumentTypeId" class="DocumentType" />
EmployeeDocumentType对象中的数据正确,但当我将详细信息保存到EmployeeDocumentType中时,它给出的错误为
此计数为14的SqlParameterCollection的索引14无效
可能的问题是什么。这个问题(几乎可以肯定)与双重映射有关
检查映射文件以查找可以使用column=“DocumentTypeId”
的其他位置
(或者根据一些默认约定,如name=“DocumentTypeId”
)
这里的解决方案很简单,其中一个必须标记为只读
<property name="DocumentTypeId" column="DocumentTypeId"
insert="false" update="false"/>
<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" />