I believe this issue is caused by the ignoring of the FetchKind property.
I have an employee table:
Employee
{
ID
Name
PositionCode
}
and a position table:
Position
{
Code
Description
}
I've joined these tables using Mapping.ByCode and set Fetch to Join, but it doesn't seem to be working.
I've looked over a dozen stack overflow posts asking the same question, but can't seem to get a clear answer.
public class EmployeeMapper: ClassMapping<Employee>
{
public EmployeeMapper()
{
Lazy(false);
Table("EMPLOYEE");
Id(x => x.Id, m => m.Column("ID");
MapToOne(c => c.PositionCode, posMap =>
{
posMap.Lazy(LazyRelation.NoLazy);
posMap.Fetch(FetchKind.Join)
posMap.Column("CODE");
}
}
}
I've used the NHibernate profiler and it behaved as follows:
Select all employees
foreach employee
select position
Note that this isn't one sql select, if there are 1000 employees, this expands out to 1001 select statements (one for all employees, then one per position).
If anyone can help it would be greatly appreciated.