Hi,
I'm having a problem with associations. Basically any attempt to use eager loading, or to create criteria spanning an association fails with the following exception:
Code:
The value "System.Object[]" is not of type "Domain.object1" and cannot be used in this generic collection.
at System.ThrowHelper.ThrowWrongValueTypeArgumentException(Object value, Type targetType)
at System.Collections.Generic.List`1.VerifyValueType(Object value)
at System.Collections.Generic.List`1.System.Collections.IList.Add(Object item)
at NHibernate.Util.ArrayHelper.AddAll(IList to, IList from)
at NHibernate.Impl.SessionImpl.Find(CriteriaImpl criteria, IList results)
Some representative mappings:
Code:
<class name="Domain.object1, Domain" table="object1">
<id name="objectID" column="object_nbr" type="Int32">
<generator class="assigned" />
</id>
<property name="prop1" column="prop1" type="Decimal" />
<many-to-one name="Object2" class="Domain.object2, Domain" column="object2_id" not-null="true" />
<many-to-one name="Object3" class="Domain.object3, Domain" column="object3_id" not-null="true"/>
</class>
<class name="Domain.object2, Domain" table="object2">
<id name="object2_id" column="object_nbr" type="Int32">
<generator class="assigned" />
</id>
<property name="name" column="prop1" type="Decimal" />
<set name="Object1s" inverse="true">
<key column="object2_id" />
<one-to-many class="Domain.object1, Domain" />
</set>
</class>
<class name="Domain.object3, Domain" table="object3">
<id name="object3_id" column="object_nbr" type="Int32">
<generator class="assigned" />
</id>
<property name="name" column="prop1" type="Decimal" />
</class>
If I specify fetch=join on either of the many-to-one mappings then I get the exception above - the same happens if I attempt to use a criteria like so:
Code:
criteria = DetachedCriteria.For<Object1>()
.CreateCriteria("Object2")
.Add(Expression.Eq("prop1", value));
Straightforward queries using just Object1 succeed OK (as long as the fetch mode is lazy)
It's most likely that I'm getting something wrong here, so can anyone point me in the right direction?