• 使用Dapper参数化查询(二)


    查询封装

    /// <summary>
        /// 分页查询条件
        /// </summary>
        public class PageWhere
        {
            /// <summary>
            /// 
            /// </summary>
            public QueryWhere queryWhere { get; set; }
            /// <summary>
            /// 每页显示数量
            /// </summary>
            public int pageSize { get; set; }
            /// <summary>
            /// 第几页
            /// </summary>
            public int pageIndex { get; set; }
            /// <summary>
            /// 排序字段
            /// </summary>
            public string filedOrder { get; set; }
        }
    
        /// <summary>
        /// 查询条件
        /// </summary>
        public class QueryWhere
        {
            public QueryWhere()
            {
                listWhere = new List<string>();
                dicWhere = new List<DicWhere>();
            }
            /// <summary>
            /// 查询条件
            /// </summary>
            public List<string> listWhere { get; set; }
            /// <summary>
            /// 赋值
            /// </summary>
            public List<DicWhere> dicWhere { get; set; }
        }
    
        /// <summary>
        /// 字段==值
        /// </summary>
        public class DicWhere
        {
            /// <summary>
            /// 字段
            /// </summary>
            public string filed { get; set; }
            /// <summary>
            /// 对应值
            /// </summary>
            public object value { get; set; }
        }

    转换为dapper的dy

    QueryParameter qp = new QueryParameter();
    qp.listWhere = pageWhere.queryWhere.listWhere;
    pageWhere.queryWhere.dicWhere.ForEach(item =>
    {
       qp.dynamicParameter.Add(item.filed, item.value);
    });
    return _prerecordBLL.GetList(qp, pageWhere.pageSize, pageWhere.pageIndex, pageWhere.filedOrder);

    调用

    if (!string.IsNullOrWhiteSpace(gltxtcinput.Text))
    {
       qw.listWhere.Add(" a.cinput=@cinput ");
       qw.dicWhere.Add(new DicWhere() { filed = "@cinput", value = gltxtcinput.EditValue });
    }
  • 相关阅读:
    es 6.7.2
    nginx https
    es 遍历
    bloomfilter
    CentOS8安装JDK1.8
    vmware快速搭建k8s集群 (vmware16|centos8|docker19.03.15|k8s1.16.9|calico3.16)(kubeadm安装方式)
    Nmap扫描结果转换xml>html
    SpringBoot 分环境打包
    JetBrains 里不为人知的秘密(16)CLion 修改for 模板最新(20220519) 大飞
    elementui 之upload 文件上传
  • 原文地址:https://www.cnblogs.com/shuaimeng/p/13962616.html
Copyright © 2020-2023  润新知