如何为以下SQL查询语句编写流畅的nhibernate查询:
select iseat.companynr, mdata.Employeenr from IDepartment as iseat inner join
Employee as i on i.pkey = iseat.employeefk
inner join employeedata as edata on edata.employeefk = i.pkey
我已经创建了类IDepartment
,Employee
和Employeedata
,还创建了一个类CompanyNr2EmployeeNrMap
,其中包含2个属性CompanyNr
和{{ 1}}。
查询需要将companynr列表作为参数并返回EmployeeNr
列表。
答案 0 :(得分:1)
var query = from emp in session.Query<Employee>()
from department in emp.Departments
select new CompanyNr2EmployeeNrMap
{
CompanyNr = department.CompanyNr,
EmployeeNr = emp.Data.EmployeeNr
};
return query.ToList();