mpnet wrote:
I'm using NHIBERNATE 1.2.0.GA version.
Here are the entities:
public class Union
{
private Dictionary<DateTime, Holiday2> _holidays2;
public virtual Dictionary<DateTime, Holiday2> Holidays2 { get { return _holidays2; } set { _holidays2 = value; } }
// ... other stuff ...
}
public class Holiday2
{
private string _holidayName;
public virtual string HolidayName
{
get { return _holidayName; }
set { _holidayName = value; }
}
}
Inside Union.hbm.xml, here is the map definition:
<map name="Holidays2" table="Holiday" generic="true">
<cache usage="read-write" />
<key column="UnionId" foreign-key="ApplicationId" />
<index column="HolidayDate" type="DateTime" />
<composite-element class="Holiday2">
<property name="HolidayName" column="HolidayName" type="string" />
</composite-element>
</map>
THIS FAILS:
Here is the error I get:
Unable to cast object of type 'NHibernate.Collection.Generic.PersistentGenericMap`2[System.DateTime,Braveline.WRS.Core.Holiday2]' to type 'System.Collections.Generic.Dictionary`2[System.DateTime,Braveline.WRS.Core.Holiday2]'.
I've been banging my head on the keys for this one, even trying to debug the NHibernate code...
any ideas, suggestions???
You need to change your Dictionary<DateTime, Holiday2> to be an IDictionary<DateTime, Holiday2>. NHibernate changes your collection at run time to be it's own persistence aware collection. Provided your initial collection (Dictionary) and it's own collection PersistentGenericMap utilize the same interfaces it can change out your collection for its own.
Change your class to use an interface for it's property and field instead, and all of your issues will go away.