What's causing “Invalid index nn for this SqlP

2019-06-24 18:45发布

问题:

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