Reputation: 3431
I have this method, receive a list of integer, and must return an Collection of EmployeeComments, the problem is I don't know how take each result of the criteria and Add to the List of 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;
}
}
how can I do this?
Upvotes: 0
Views: 199
Reputation: 37749
In this case you should use Restrictions.In as follows:
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>();
}
}
Upvotes: 2