“Count = n的SqlParameterCollection的无效索引n” OR“外键不能为空” [英] "Invalid Index n for this SqlParameterCollection with Count=n" OR "foreign key cannot be null"

查看:188
本文介绍了“Count = n的SqlParameterCollection的无效索引n” OR“外键不能为空”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经成功地使用了NHibernate很久了,
已经能够解决很多陷阱,我用
开发的一个应用程序正在运行。最近的障碍
真的让我挠脑袋。

最近我不得不用一些新的类来扩展类库,
作为子类嵌套到一些已经存在的类中。我刚刚复制
的聚合映射相同的模型,我已经成功
使用,但这一次是行不通的。



现在,当我在父映射文件中使用以下代码时:

 < bag name =SeaInfoItemstable =EDIImport_SeaInfolazy =falsecascade =save-update> 
< key column =EDI_FK_OWNERID/>
< one-to-many class =FargoGate.AppLib.EdiImportSeaInfo,FargoGate.AppLib/>
< / bag>

我可以选择在子类中使用:

 < property name =EDI_FK_OWNERIDcolumn =EDI_FK_OWNERID/> 

...这给我臭名昭着的
SqlParameterCollection Invalid Index n with Count = n错误。



或者我尝试使用这个解决方案后,发现一些谷歌搜索:

 < property name =EDI_FK_OWNERIDcolumn =EDI_FK_OWNERIDinsert =falseupdate =false/> 

...这给了我一个无法将值NULL插入列
'EDI_FK_OWNERID '...列不允许空值。错误。因此,基本上我必须在害虫和霍乱之间做出选择。

我没有得到的是它对于已经存在的
聚合类完美地工作,我真的不能发现这个差异。唯一的
是这个外键(EDI_FK_OWNERID)可以引用两个
不同的父表。坏的数据库设计,我知道,但我没有
的设计,这是我的任务,开发它好或坏。我无法改变数据库设计。另一个区别是我完全从已经存在的子类(映射以及类成员)中移除了外键引用。我试图模仿,当然,但无济于事。

我还发现,一个新的类(这是相当小)也工作正常。但是我也看不出在这里有什么不同。我很难过!

任何人都有线索?

解决方案

对于这个臭名昭着的Count = n的SqlParameterCollection无效索引n,我忽略了一个错误,我忽略了这个显而易见的错误:一个类的重复映射。
在这个特定的映射中,我留下了这个错误,其中主键也被定义为一个属性:

 < id name =IDcolumn =ID> 
< generator class =guid/>
< / id>
< property name =IDcolumn =ID/>

现在浪费时间去调试了!


I have been successfully using NHibernate for quite some time now and have been able to solve a lot of pitfalls with an application that I developed with it and that is running in production. The recent hurdle really has me scratching my head, though.

Recently I had to expand the class library with some new classes that are nested as children to some already existing classes. I just copied the same model for aggregate mapping that I already was successfully using, but this time it does not work.

Now when I use the following in the parent mapping file:

  <bag name="SeaInfoItems" table="EDIImport_SeaInfo" lazy="false" cascade="save-update"> 
     <key column="EDI_FK_OWNERID"/> 
     <one-to-many class="FargoGate.AppLib.EdiImportSeaInfo, FargoGate.AppLib"/> 
  </bag> 

I can choose to, in the child class, either use:

  <property name="EDI_FK_OWNERID" column="EDI_FK_OWNERID" /> 

...which gives me the infamous "Invalid Index n for this SqlParameterCollection with Count=n" error.

OR I try with this solution I found after some Googling:

   <property name="EDI_FK_OWNERID" column="EDI_FK_OWNERID" insert="false" update="false" /> 

...which gives me a "Cannot insert the value NULL into column 'EDI_FK_OWNERID'... column does not allow nulls." error.

So basically I have to choose between pest and cholera.

What I don't get is that it works flawlessly for the already existing aggregate classes, and I really cannot spot the difference. The only thing is that this foreign key (EDI_FK_OWNERID) could refer to two different parent tables. Bad database design, I know, but I didn't design it, and it is my task to develop up to it for better or worse. I cannot change the database design.

The other difference is that I totally removed the foreign key reference from the already existing child classes (the mappings as well as the class members). I tried to emulate that of course, but of no avail.

Also I discovered that one of the new classes (which is quite small) also works fine. But I cannot see what the difference is here either. I am stumped!

Anyone has a clue?

解决方案

Aaargh! I was put so much on a wrong leg with this infamous "Invalid Index n for this SqlParameterCollection with Count=n" error that I overlooked the obvious: A duplicate mapping of a field for ONE of the classes. In that particular mapping I left this error, where the primary key is also defined as a property:

 <id name="ID" column="ID">
   <generator class="guid" />
 </id>
 <property name="ID" column="ID" /> 

Now that was a waste of time trying to debug that!

这篇关于“Count = n的SqlParameterCollection的无效索引n” OR“外键不能为空”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆