I've got an NHibernate entity class (LogItem) with one of it's properties property mapped as any representing the parent to which the LogItem belongs. The any mapping uses the meta-type tag to specify the strategy for the names persisted to the classes represented.
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" namespace="Core.Entities" assembly="Core" default-access="field.camelcase">
<class name="LogItem" table="Logs" lazy="true">
<id name="Id" column="LogID" unsaved-value="0" >
<generator class="native" />
</id>
<property name="Message" column="Message" length="4000" />
<property name="Severity" column="Severity" />
<any name="ParentEntity" id-type="Int32" meta-type="string" >
<meta-value value="Core.Entities.Customer" class="Customer"/>
<meta-value value="Core.Entities.Trigger" class="Trigger"/>
<meta-value value="Core.Entities.User" class="User"/>
<column name="ParentEntityType"/>
<column name="ParentEntityID"/>
</any>
</class>
</hibernate-mapping>
When executing a query that instantiates a new POCO entity (not an NHibernate entity) using the following query...
Code:
SELECT new DTItem(log.Id, log.ParentEntity.class, log.ParentEntity.id) FROM LogItem log
...where the DTItem class is as follows...
Code:
public class DTItem
{
public int ItemId;
public object ParentEntityType;
public int ParentEntityId;
public DTItem()
{}
public DTItem(int id, object parentEntityType, int parentEntityId)
{
this.ItemId = id;
this.ParentEntityType = parentEntityType;
this.ParentEntityId = parentEntityId;
}
}
...the parentEntityType in the constructor is null.
The parentEntityId has a value and I've looked in the log4net debug output and seen that the string specified in the mapping is being returned in the resultset, so I have to assume that there's a problem in the NHibernate code that generates the new object returned when the '.class' special property is used in a query (I'm just expecting object, but I would assume that it's going to return a System.Type, right?).
Can anyone else confirm that this is a bug?
Cheers,
Symon.