美文网首页
C# linq 条件查询 多条件、追加条件

C# linq 条件查询 多条件、追加条件

作者: Charles2018 | 来源:发表于2023-08-04 17:25 被阅读0次
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