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 });
    }
  • 相关阅读:
    LeetCode20 有效的括号
    函数的多个参数
    定义一个函数的基本语法 函数的参数
    函数
    金字塔
    水仙花数
    百鸡百钱
    循环demo
    while适用于不确定循环次数
    浏览器打断点
  • 原文地址:https://www.cnblogs.com/shuaimeng/p/13962616.html
Copyright © 2011-2022 走看看