是什么导致“此 SqlParameterCollection 的索引 nn 无效,且 Count=nn”?当数据库中的列为空时?
对于 Accommodation 实体,我们有两列可为空:CollectionType
和 AccommodationUnitType
。
但是我注意到数据中它们被设置为零而不是 null,导致 NHibernate 尝试查找 id 为 0 的实体。这是很多额外不必要的数据库调用,因此我将数据库中的相关数据更新为 NULL,突然我得到了一个很大的错误:
“此索引 24 无效 计数 = 24 的 SqlParameterCollection"
这是我正在使用的映射覆盖:
public void Override(AutoMapping<Core.Entities.Itinerary.Accommodation.Accommodation> mapping)
{
...
mapping.References(x => x.CollectionType).Nullable();//.Not.LazyLoad();
mapping.References(x => x.AccommodationUnitType).Nullable();//.Not.LazyLoad();
Cache.Is(c => c.ReadWrite());
}
Google 有很多答案,但似乎与我的问题没有任何关系。
有什么想法吗?
编辑< /em> 有关信息,属性是实体,因此可以为空:
public virtual AccommodationUnitType AccommodationUnitType { get; set; }
public virtual AccommodationCollectionType CollectionType { get; set; }
For Accommodation entity we have two columns that are nullable: CollectionType
and AccommodationUnitType
.
However I noticed in the data that they were set to zero rather than null, causing NHibernate to try and find an entity with id 0. This was a lot of extra unnecessary DB calls, so I updated the relevant data to NULL in the database, and suddenly I get a big fat error:
"Invalid index 24 for this
SqlParameterCollection with Count=24"
Here is the mapping override I'm using:
public void Override(AutoMapping<Core.Entities.Itinerary.Accommodation.Accommodation> mapping)
{
...
mapping.References(x => x.CollectionType).Nullable();//.Not.LazyLoad();
mapping.References(x => x.AccommodationUnitType).Nullable();//.Not.LazyLoad();
Cache.Is(c => c.ReadWrite());
}
Google has lots of answers that don't seem to have anything to do with my problem.
Any ideas?
Edit
For info the properties are entities, so are nullable:
public virtual AccommodationUnitType AccommodationUnitType { get; set; }
public virtual AccommodationCollectionType CollectionType { get; set; }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“CollectionType”和“AccommodationUnitType”是否都指定为“int”?
当使用空值时,您需要将它们都指定为“int?”。
不确定这是否是您遇到的问题,但它为我纠正了类似的问题。
Are "CollectionType" and "AccommodationUnitType" both designated as "int"?
When working with nulls you would need to designate them both as "int?".
Not sure if this is the problem you are having but it corrected something similar for me.