学海无涯

导航

Dapper模糊查询 Like

public async Task<IReadOnlyList<ProductView>> GetProductViewAsync(ProductQueryParameter queryParameter)
  {
    if (!string.IsNullOrEmpty(queryParameter.Name))
    {
      queryParameter.Name = $"%{queryParameter.Name}%";
    }
    string sql = "select * from ProductView where (Code=@Code or @Code='') and (Name like @Name or @Name='')" +
      " and (TechnologyCode=@TechnologyCode or @TechnologyCode='')";
    using var conn = _dapperContext.CreateConnection();
    var list = await conn.QueryAsync<ProductView>(sql, queryParameter);
    return list.ToList();
  }

  

posted on 2023-09-05 21:54  宁静致远.  阅读(237)  评论(0编辑  收藏  举报