是什么导致“此 SqlParameterCollection 的索引 nn 无效,且 Count=nn”?当数据库中的列为空时?

发布于 2024-10-15 00:33:09 字数 987 浏览 3 评论 0原文

对于 Accommodation 实体,我们有两列可为空:CollectionTypeAccommodationUnitType

但是我注意到数据中它们被设置为零而不是 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 技术交流群。

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

发布评论

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

评论(1

信愁 2024-10-22 00:33:09

“CollectionType”和“AccommodationUnitType”是否都指定为“int”?

当使用空值时,您需要将它们都指定为“int?”。

不确定这是否是您遇到的问题,但它为我纠正了类似的问题。

public virtual int? CollectionType {get;set;}
public virtual int? AccommodationUnitType {get;set;}

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.

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