What's causing “Invalid index nn for this SqlParameterCollection with Count=nn” when a column is Null in the database?

浪尽此生 提交于 2019-12-10 16:17:08

问题


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

回答1:


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


来源:https://stackoverflow.com/questions/4861071/whats-causing-invalid-index-nn-for-this-sqlparametercollection-with-count-nn

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!