Site Loading

Nhibernate Error: Invalid index N for this SqlParameterCollection with Count=N

This error came up this week when I was working with one of the applications we have.  The first thing I tried is using Profiler to see what SQL was being generated.  But the strange thing was that I could not see any Insert statement.

Eventually I found the cause of the error.  I had added some properties to the nhibernate mapping file:

<property name="property1" type="String(100)" column="property1" />
<property name="property2" type="String(100)" column="property1" />
<property name="property3" type="Int32" column="property1" />
<property name="property4" type="Int32" column="property1" />

I had missed the fact that I had pointed them to the same field in the table.  So the Xml should have been:

<property name="property1" type="String(100)" column="property1" />
<property name="property2" type="String(100)" column="property2" />
<property name="property3" type="Int32" column="property3" />
<property name="property4" type="Int32" column="property4" />

I would assume you would get the same error for fluent nhibernate.

Close