public long GetParentEmpIdForSubAccount(long empId)
IQuery q = NHSession.GetNamedQuery("GetSubAccounts")
.SetInt64("EmpId", empId);
var subAccounts = q.List();
if (subAccounts == null || subAccounts.Count == 0)
var firstRow = (Object[])subAccounts[0];
return (long)firstRow[0];
<sql-query name="GetSubAccounts" cacheable="true" read-only="true">
SELECT DISTINCT subs.EmpIdParent, emp.EMP_ID, emp.EMP_ESD_NBR, emp.EMP_LEGAL_ENTY_NAME
FROM [NGT540].[vw_EmployerRelationship] base
JOIN [NGT540].[vw_EmployerRelationship] subs ON base.EmpIdParent = subs.EmpIdParent --in case @Emp_ID is the subAcct
JOIN [NGT540].[TBL_EMPR_EMP] EMP ON emp.EMP_ID = subs.EmpId
WHERE base.[EmpId] = :EmpId
AND (emp.EMP_ID <> :EmpId OR (:IncludeParent = 1 AND base.EmpIdParent = emp.EMP_ID))
<query-param name="IncludeParent" type="Boolean"/>