views:

147

answers:

2

Hi

I'm getting a strange NHibernate exception when I try and create a SessionFactory. I've narrowed down the exception 'Unable to cast object of type 'NHibernate.Mapping.Bag' to type 'NHibernate.Mapping.IKeyValue' to the following mapping on the Company object:

<bag name="Images" cascade="none">
  <key column="CompanyId" property-ref="Images"/>
  <one-to-many class="GwDbImage"/>
</bag>

This is the mapping for GwDbImage:

<class name="GwDbImage" table="Images" >
<id name="ImageId">
  <column name="ImageId" sql-type="int" not-null="true"/>
  <generator class="native"/>
</id>

<property name="FileName"  />

The definition of Images on the Company object is as follows:

public virtual IList<GwDbImage> Images { get; set; }

I know it's vague but does anyone know what is wrong / point me in the right direction?

Thanks

Jon

A: 

you declared Images property as IDictionary while bag should be declared as IList

Alex Reitbort
Already checked that, it's declared as IList
Jon
A: 

Why did you specify the property-ref attribute ? Is it necessary in your case ? Do you join with another column other then your PK in your related table ?

Frederik Gheysels