我有这个方法,收到一个整数列表,并且必须返回一个EmployeeComments的集合,问题是我不知道如何取每个条件的结果并添加到EmployeeComments列表中:
public ICollection<EmployeeComments> GetAllEmployeeCommentsByIdEmployee(List<int> idEmployeeList)
{
List<EmployeeComments> employeeCommentsList = new List<EmployeeComments>();
using (ISession session = NHibernateSessionBuilder.OpenSession())
{
foreach (int idEmployee in idEmployeeList)
{
employeeCommentsList = session
.CreateCriteria(typeof(EmployeeComments))
.Add(Restrictions.Eq("IdEmployee", idEmployee)).List<EmployeeComments>();
}
return employeeCommentsList;
}
}
我该怎么做?
答案 0 :(得分:2)
在这种情况下,您应该使用Restrictions.In,如下所示:
public ICollection<EmployeeComments> GetAllEmployeeCommentsByIdEmployee(IEnumerable<int> idEmployeeList)
{
using (ISession session = NHibernateSessionBuilder.OpenSession())
{
return session
.CreateCriteria(typeof(EmployeeComments))
.Add(Restrictions.In(Projections.Id(), idEmployeeList.ToArray()))
.List<EmployeeComments>();
}
}