如何为这个sql语句编写nhibernate查询

时间:2013-09-02 09:53:15

标签: fluent-nhibernate

如何为以下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

我已经创建了类IDepartmentEmployeeEmployeedata,还创建了一个类CompanyNr2EmployeeNrMap,其中包含2个属性CompanyNr和{{ 1}}。

查询需要将companynr列表作为参数并返回EmployeeNr列表。

1 个答案:

答案 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();