简体   繁体   中英

Nhibernate Query to compare if item present in list

I want to write a nhibernate query to get all employees who are in the given list of departments.

The senario is the employee class has the department class property.the department class has the department name in it besides other properties.I have a list of department names with me and i want all employees who belong to that department. The below is the query i tried but its not working

var employeesInGivenDepartmentList = NHibernateSessionManager.GetSession().CreateCriteria(typeof(Employee), "emp") .CreateAlias("emp.Department", "dept") .Add(Restrictions.In("dept.Name", departmentlist)) //this line not working .SetResultTransformer(new DistinctRootEntityResultTransformer()) .List(); Thanks

the below code works. its resolved now. var employeesInGivenDepartmentList = NHibernateSessionManager.GetSession().CreateCriteria(typeof(Employee), "emp") .CreateAlias("emp.Department", "dept") // i missed this line before for the similar object .Add(Restrictions.In("dept.Name", departmentlist))
.SetResultTransformer(new DistinctRootEntityResultTransformer()) .List()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM