The title is maybe a bit confusing, but my problem is as follows:
I have a class, which contains an IDictionary.
This IDictionary has a simple string as its key, and as 'value', it contains instances of another class.
In short, this class looks as this:
Code:
public class Class1
{
private int _id;
private IDictionary<string, Class2> _dictionary;
}
The mapping of this class, looks like this:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="Domain.Class1, Domain" table="Table1" lazy="false">
<id name="Id" access="field.camelcase-underscore" column="ProjectId" unsaved-value="-1">
<generator class="identity" />
</id>
<map name="_class2Collection" access="field" table="Table2" lazy="false" cascade="all" inverse="true" >
<key column="Id" />
<index column="Language" type="string" />
<one-to-many class="Domain.Class2, Domain" />
</map>
</class>
</hibernate-mapping>
So, when I remove an item from the _dictionary member of class1, this does not result in a DELETE statment generated by NHibernate. NHibernate doesnt do anything.
Then, I thought about removing the 'inverse=true' attribute from the mapping; in this case, NHibernate generates an UPDATE statement: It wants to set the key (Id) and index (Language) column of Table2 to NULL (which is not allowed), instead of deleting the record from Table2.
(I must also say that my 'Class2' contains yet another dictionary wich just contains keys of type string and values of type string. When I remove an item from this dictionary, the items are deleted like they should be).
What am i missing ? What am i doing wrong ?