tags:

views:

803

answers:

2

Hi,

I have an MVC app using NHibernate.

I created a model and tried to insert data into the db for the first time with NHibernate, so please go easy.

I get this error on the session.Save(object);

IndexOutOfRangeException was unhandled by user code

Invalid index 8 for this SqlParameterCollection with Count=8.

When I look at the data in the object using watch window all seems ok and also collections are inittialized.

Using SQL 2005.

Any ideas why this may be occurring please?

Malcolm

A: 

Does one of these links help?

http://groups.google.com/group/nhusers/browse_thread/thread/34f124a7052c37ff

http://www.methodicmadness.com/2009/01/nhibernate-what-is-heck-clazz.html

http://groups.google.com/group/fluent-nhibernate/browse_thread/thread/116c822c44aae797

If not, you'll have to post your mapping to get additional advice.

I suggest troubleshooting this by first isolating the insert into a unit test.

Jamie Ide
+3  A: 

I have had the same problem using NHibernate myself, the problem in my case was in the mapping. On my associations I have mapped a property containing the associated entity, and also a property with the association ID only.

The solution in my case was to add update="false" insert="false" to my mapping of the property containing the ID. Like this:

<property name="AssociationId" column="AssociationColumnName" update="false" insert="false" />
<many-to-one name="Association" column="AssociationColumnName" property-ref="Id" not-null="false" />
fredrik