C# linq 条件查询 多条件、追加条件
2023-08-04 本文已影响0人
Charles2018
Expression<Func<Module, bool>> exp = x => true;
if(queryDto.Name is not null)
{
exp = exp.And(x => (x.Name ?? String.Empty).StartsWith(queryDto.Name));
}
if(queryDto.Url is not null)
{
exp = exp.And(x => (x.LinkUrl ?? String.Empty).StartsWith(queryDto.Url));
}
var page = await _moduleRepository.GetPagedAsync(queryDto,exp,x => x.Id);
return ObjectMapper.Map<ResponsePage<Module>, ResponsePage<ModuleDto>>(page);