Hello,
My problem occurs since the upgrade from NHibernate 1.0.2 to NHibernate 2.0.
In my container class, I have a IDictionary collection which key is an Object (MyKeyClass), and values also are objects (MyValueClass).
The problem is when I try to access one of the element of the list by the key, I get an error stating that the key is not present in the collection.
But when I look at the container class in debug mode, it seems that the collection is correctly filled.
Example: myContainerClass.m_MyList[aMyKeyClass] -> will always fail.
My code:
public class MyContainerClass
{
protected IDictionary m_MyList;
}
public class MyKeyClass
{
int id;
... // some other properties...
public override bool Equals(object obj)
{
if (obj == null || GetType() != obj.GetType())
return false;
MyKeyClass anObject = (MyKeyClass)obj;
return (id.Equals(anObject.id));
}
public override int GetHashCode()
{
return id.GetHashCode();
}
}
Mapping is like this:
<map name="MyList" cascade="all" access="field.pascalcase-m-underscore" lazy="true">
<key column="KEY_OF_CONTAINER"/>
<index-many-to-many column="KEY_OF_KEYCLASS" class="MyKeyClass"/>
<one-to-many class="MyValueClass"/>
</map>
MyKeyClass and MyValueClass are also mapped, but I don't think showing them will help here.
Also, I tried to use generic IDictionary instead, but I get the same error.
This error didn't occur with NHibernate 1.0.2
Thanks for your help.
|