我得到以下代码
public class Personnel {
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public int OrganizationalUnitId { get; set; }
public int RoleId { get; set; }
}
private List<Expression<Func<Personnel, bool>>> personnelFilter;
public void AddFilter(Expression<Func<Personnel, bool>> filter)
{
this.personnelFilter.Add(filter);
}
public IEnumerable<Personnel> GetResult()
{
IQueryable<Personnel> personnel = Store.Instance.Query<Personnel>();
foreach(var filter in this.personnelFilter)
{
personnel = personnel.Where(filter);
}
return personnel;
}
它现在使用 AND,因为它会将 Where 子句附加到已过滤的查询中。但我不想将其添加为 AND,而是添加为 OR。
所以假设我添加了过滤器:
model.AddFilter(a => a.FirstName == "Test")
model.AddFilter(a => a.FirstName == "More")
// Or adding something stupid like:
model.AddFilter(a => a.OrganizationalUnit == 1)
model.AddFilter(a => a.OrganizationalUnit == 1)
我想要以下查询:
WHERE Firstname == "Test" || Firstname == "More"
不做:
model.AddFilter(a => a.FirstName == "Test" || a.FirstName == "More")
这可能吗?换句话说,我得到了一个带有表达式的列表,我想在 where 子句中对它们进行 OR 操作而不是 AND,但我找不到让它工作的方法。有任何想法吗?