Possible Duplicate:
How do I combine LINQ expressions into one?
public bool IsUnique(params Expression<Func<Employee, bool>>[] properties)
{
var combinedProperties = Combine(properties);
var rowCount = _session.QueryOver<Employee>().Where(combinedProperties).ToRowCountQuery().RowCount();
return rowCount == 0;
}
Expression<Func<Employee, bool>> Combine(Expression<Func<Employee, bool>>[] properties)
{
???
}
Usage:
var isUnique = _employeeRepository.IsUnique(x => x.FirstName == commandMessage.FirstName, x => x.LastName == commandMessage.LastName);
Is there a way of combining predicates with an AND operator?
The simplest way would be to loop over your params array and call .Where for each expression.
I know this isn’t precisely what you asked, but it may be good enough as it achieves the overall goal?