zoukankan      html  css  js  c++  java
  • 使用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 });
    }
  • 相关阅读:
    如何编写gitignore文件
    【转】three.js详解之入门篇
    【转】Nginx反向代理和负载均衡
    【转】使用nvm快速搭建 Node.js 开发环境
    【转】npm包管理器那些事
    【转】用systemJS+karma+Jasmine+babel环境去编写简单的ES6工程
    个人博客 总览
    【转】vscode: Visual Studio Code 常用快捷键
    【转】Cmder--Windows下命令行利器
    APScheduler+Flask
  • 原文地址:https://www.cnblogs.com/shuaimeng/p/13962616.html
Copyright © 2011-2022 走看看