tags:

views:

847

answers:

2

I'm getting the following error: Unable to cast object of type 'NHibernate.Collection.Generic.PersistentGenericSet to type 'Iesi.Collections.Generic.SortedSet.

Invalid mapping information specified for type [Type], check your mapping file for property type mismatches".

Here's my set definition:

<set name="ProcessTrackerDetails" lazy="true" access="field.camelcase-underscore" 
                sort="natural" cascade="all" inverse="true">
  <key column="ProcessTrackerDetailsID"/>
  <one-to-many class="ProcessTrackerDetail"></one-to-many>
</set>

And heres the code:

private Iesi.Collections.Generic.SortedSet<ProcessTrackerDetail> _processTrackerDetails = new SortedSet<ProcessTrackerDetail>();

Suggestions?

+3  A: 

NHibernate requires interfaces. Try to use ISet<ProcessTrackerDetail> instead of SortedSet<ProcessTrackerDetail>

Sly
I'm not sure if you mean to try to instantiate that interface (Doesn't work)... Or if you mean use a Set instead of a sorted set (Doesn't work either, I need a sorted set)...There's probably something fundamental I'm missing here.
Gary
You need to use interfaces in classes instead of classes. Interfaces is required for nhibernate to track down changes made to the collections.
Sly
+2  A: 

Change your code to define _processTrackerDetails using the ISet interface.

private ISet<ProcessTrackerDetail> _processTrackerDetails = 
    new SortedSet<ProcessTrackerDetail>();

You can still assign it to a SortedSet, but I am not sure that it does much when lazy loaded as NHibernate will use it's ISet implementation to do the lazy loading. The sort="natural" in your mapping should take care of the sort order.

g .