I have a data structure which uses composite ids (Which I dont wish to change to single) Everything loads fine except for many-to-one joins which if the join is empty, instead of mapping the property to null, maps it to an empty proxy object. I have written an ugly work around( see bleow). Any solutions to this?
private Node _Parent;
public Node Parent
{
get
{
return this._Parent;
}
set
{
this._Parent = Proxy.Check<Node>(value);
}
}
internal static class Proxy
{
public static T Check<T>(T obj) where T : PersistentObject
{
if (obj is NHibernate.Proxy.INHibernateProxy && obj != null)
{
try
{
int id = obj.ID;
return obj;
}
catch //Proxy only object cant retrieve ID
{
return null;
}
}
else
{
return obj;
}
}
}
with the mapping file beginning
<class name="Node" table="Node">
<composite-id>
<key-property name="ID"/>
<key-property name="VersionID"/>
</composite-id>
and accessed by
<many-to-one name="Node" class="Node" >
<column name="NodeID"/>
<column name="VersionID" />
</many-to-one>