【发布时间】:2015-11-13 12:58:00
【问题描述】:
当过滤器属性具有值(非空)时,我想使用 where 条件构建查询。如果使用多个过滤器,则它们必须是 AND 组合。
当相应的属性值不为空时,如何组合/添加每个谓词以使最终查询准备好进行过滤?
IQueryable<Customer> filter = null;
Expression<Func<Customer, bool>> predicatetest1 = res => res.test1 == request.test1;
Expression<Func<Customer, bool>> predicatetest2 = res => res.test2 == request.test2;
Expression<Func<Customer, bool>> predicatetest3 = res => res.test3 == request.test3;
if (request.test1 != null)
{
// add the above predicate to the filter
}
if (request.test2 != null)
{
// add the above predicate to the filter
}
if (request.test3 != null)
{
// add the above predicate to the filter
}
【问题讨论】:
标签: entity-framework linq-to-entities iqueryable