谓词构建器选择所有替代项

时间:2018-09-12 13:11:14

标签: c# .net predicate

我正在为应用创建过滤器,我有两种方法访问同一窗口,第一种方法是我传递代码并获取所有记录,第二种方法是当我需要获取所有记录时< strong> code 为空或为空。搜索了很多解决方案,但没有找到

var predicate = PredicateBuilder.New<Foo>();

if (!string.IsNullOrEmpty(requestModel.code))
{
    predicate = predicate.And(x => x.code == requestModel.code);
}

if (string.IsNullOrEmpty(requestModel.code))
{
    //here I want to get all records from table
}

return await context.Foo
  .AsExpandable()
  .Where(predicate)
  .ToListAsync(cancellationToken);

0 个答案:

没有答案