title: What's causing "Invalid index nn for this SqlParameterCollection with Count=nn" when a column is Null in the database?
body: <p>For Accommodation entity we have two columns that are nullable: <code>CollectionType</code> and <code>AccommodationUnitType</code>.</p>
  
  <p>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:</p>
  
  <blockquote>
    <p>"Invalid index 24 for this
    SqlParameterCollection with Count=24"</p>
  </blockquote>
  
  <p>Here is the mapping override I'm using:</p>
  
  <pre><code>    public void Override(AutoMapping&lt;Core.Entities.Itinerary.Accommodation.Accommodation&gt; mapping)
      {
          ...
          mapping.References(x =&gt; x.CollectionType).Nullable();//.Not.LazyLoad();
          mapping.References(x =&gt; x.AccommodationUnitType).Nullable();//.Not.LazyLoad();
          Cache.Is(c =&gt; c.ReadWrite());
      }
  </code></pre>
  
  <p>Google has lots of answers that don't seem to have anything to do with my problem.</p>
  
  <p>Any ideas?</p>
  
  <p><em><strong>Edit</em></strong> 
  For info the properties are entities, so are nullable:</p>
  
  <pre><code>public virtual AccommodationUnitType AccommodationUnitType { get; set; }
  public virtual AccommodationCollectionType CollectionType { get; set; }
  </code></pre>