This is what i have:
class Unit
{
public Position ManagerPosition;
}
<sql-query name="GetUnits" read-only="true">
<query-param name="UserGroupId" type="int"/>
<query-param name="RelevantToDate" type="datetime"/>
<query-param name="ParentUnitId" type="int"/>
<return class="Unit" />
...
</sql-query>
<sql-query name="GetPositions" read-only="true">
<query-param name="UserGroupId" type="int"/>
<query-param name="RelevantToDate" type="datetime"/>
<query-param name="UnitId" type="int"/>
<query-param name="ManagersOnly" type="bool"/>
<return class="Position" />
...
</sql-query>
Units and Positions are in separate tables, but both filtered by UserGroupId and RelevantDate (the parameters of the appropriate named queries). they are not mapped to the tables directly because of the complexity of their properties.
What i'm trying to do is to get a list of Units with a single Position which has its flag IsManager set to True.
I've tried to do it by return-join - no success. I've tried to do it by
<return class="Unit">
<return-property name="ManagerialPosition" column="position"/>
</return>
and
<return alias="position" class="Position">
but the NHibernate said that it can't cast an array of System.Object to an array of Unit.
what is better way to solve my problem? thanks in advance!
the preferable ways are:
- call a parameterized query for Position from Unit query.
- parse a resultset of a combined query to get Unit and Position properties