C# linq 条件查询 多条件、追加条件
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);
本文标题:C# linq 条件查询 多条件、追加条件
本文链接:https://www.haomeiwen.com/subject/eaovpdtx.html
网友评论