当前位置: 移动技术网 > IT编程>开发语言>.net > 使用Dapper查询记录是否存在

使用Dapper查询记录是否存在

2019年07月10日  | 移动技术网IT编程  | 我要评论

天师鬼禄,彭浩翔骂大鹏,老爸老妈浪漫史第七季

/// <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

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网