• 使用Dapper查询记录是否存在


    /// <summary>
        /// Dapper数据访问抽象基础类
        /// </summary>
        public class DapperHelper
        {
            public static string connectionString = DESEncrypt.Decrypt(ConfigurationManager.ConnectionStrings["SOACon"].ConnectionString);
            /// <summary>
            /// 连接数据库
            /// </summary>
            /// <returns></returns>
            public static IDbConnection DbConnection()
            {
                var connection = new SqlConnection(connectionString);//连接SQL Server数据库
                connection.Open();
                return connection;
            }
    
            /// <summary>
            /// 执行是否存在数据
            /// </summary>
            /// <typeparam name="T"></typeparam>
            /// <param name="sqlStr">查询(例:SELECT COUNT(1)  FROM XXX )</param>
            /// <param name="param">匿名类型</param>
            /// <returns></returns>
            public static bool Exists(string sqlStr, Object param)
            {
                using (IDbConnection conn = DapperHelper.DbConnection())
                {
                    int count = conn.Query<int>(sqlStr, param).FirstOrDefault();
                    return count > 0 ? true : false;
                }
            }
        }

    调用:

    #region 判断是否存在库存(不论热前还是热后)
    
            /// <summary>
            /// 判断是否存在库存(不论热前还是热后)
            /// </summary>
            /// <param name="processCardNumber">流转卡号</param>
            /// <returns></returns>
            public bool ExistInventory(string processCardNumber)
            {
                string sqlStr = " SELECT COUNT(1) FROM udtWip_Inventory WHERE processCardNumber=@processCardNumber ";
                return DapperHelper.Exists(sqlStr, new { processCardNumber = processCardNumber });
            }
    
    
            #endregion
  • 相关阅读:
    分布式系统之CAP原则
    第六章21
    第六章15
    第六章23
    Django框架图书管理之查看书籍与添加书籍
    Django框架之queryset数据类型
    Django框架路由设置的正则表达式
    Djiango框架之添加表记录
    Django框架图书管理之删除操作
    Django框架路由的include分发机制
  • 原文地址:https://www.cnblogs.com/schangxiang/p/11163430.html
Copyright © 2020-2023  润新知