public class Case
{
public int Id { get; set; }
public string Number { get; set; }
public Employee Employee { get; set; }
}
public class Employee
{
public int Id { get; set; }
public string EmployerIdentifier { get; set; }
public Case Case { get; set; }
}
There is a one to one releationship between Case and Employee. However there are multiple records in the DB that represent the same Employee. To find those records we look at the EmployerIdentifier. So if I have only the Employee.Id how can I write an NHibernate query that returns all the cases for that Employee. In SQL I would do it by joining to the employee table twice (see example below).
Declare @TargetEmployeeID bigint
set @TargetEmployeeID = 246834
select * from Cases C
inner join Employees E on E.EmployeeID = C.EmployeeID
inner join Employees EST on EST.EmployerIdentifier = E.EmployerIdentifier
where EST.EmployeeID = @TargetEmployeeID
How would I do this using HQL?