是什么导致“Count = nn的SqlParameterCollection的索引nn无效”当一个列在数据库中是空的? [英] What's causing "Invalid index nn for this SqlParameterCollection with Count=nn" when a column is Null in the database?

查看:87
本文介绍了是什么导致“Count = nn的SqlParameterCollection的索引nn无效”当一个列在数据库中是空的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于Accommodation住所,我们有两列可以为空: CollectionType AccommodationUnitType



然而我注意到在数据中它们被设置为零而不是null,导致NHibernate试图找到一个id为0的实体。这是很多额外的不必要的数据库调用,所以我更新在数据库中的相关数据为NULL,并突然我得到一个大胖的错误:



的索引24无效SqlParameterCollection与计数= 24

这是我使用的映射覆盖:

  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());

$ / code>

Google有很多答案似乎与我的问题。



有什么想法?

编辑
对于信息的属性是实体,所以可以为空:

  public virtual AccommodationUnitType AccommodationUnitType {get;组; } 
public virtual AccommodationCollectionType CollectionType {get;组; }


解决方案

CollectionType和AccommodationUnitType作为int?



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

不知道这是你遇到的问题,但它纠正了类似的东西。

  public virtual int? CollectionType {get; set;} 
public virtual int? AccommodationUnitType {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; }

解决方案

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

这篇关于是什么导致“Count = nn的SqlParameterCollection的索引nn无效”当一个列在数据库中是空的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆