“此 SqlParameterCollection 的索引 n 无效,且 Count=n” OR“外键不能为空”

发布于 2024-10-15 21:14:26 字数 1163 浏览 2 评论 0原文

我已经成功使用 NHibernate 一段时间了,并且 我已经能够通过我的应用程序解决很多陷阱 用它开发并正在生产中运行。最近的障碍 不过,确实让我摸不着头脑。

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

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

  <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> 

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

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

...这给了我臭名昭著的“无效索引 n SqlParameterCollection with Count=n" 错误。

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

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

...这给了我一个“无法将 NULL 值插入列 'EDI_FK_OWNERID'...列不允许空值。”错误。

所以基本上我必须在害虫和霍乱之间进行选择。

我不明白的是它对于已经存在的 聚合类,我真的看不出区别。唯一的 问题是这个外键(EDI_FK_OWNERID)可以引用两个 不同的父表。糟糕的数据库设计,我知道,但我没有 设计它,无论好坏,我的任务都是开发它。我无法更改数据库设计。

另一个区别是我完全从现有的子类(映射以及类成员)中删除了外键引用。当然,我试图模仿这一点,但没有成功。

我还发现其中一个新类(相当小)也可以正常工作。但我也看不出这里有什么区别。我被难住了!

有人有线索吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

痴梦一场 2024-10-22 21:14:26

啊啊!我被这个臭名昭著的“Invalid Index n for this SqlParameterCollection with Count=n”错误搞得一团糟,以至于我忽略了一个明显的问题:其中一个类的字段的重复映射。
在那个特定的映射中,我留下了这个错误,其中主键也被定义为一个属性:

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

现在尝试调试它是浪费时间!

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文