////// Dapper数据访问抽象基础类 /// public class DapperHelper { public static string connectionString = DESEncrypt.Decrypt(ConfigurationManager.ConnectionStrings["SOACon"].ConnectionString); ////// 连接数据库 /// ///public static IDbConnection DbConnection() { var connection = new SqlConnection(connectionString);//连接SQL Server数据库 connection.Open(); return connection; } /// /// 执行是否存在数据 /// ////// 查询(例:SELECT COUNT(1) FROM XXX ) /// 匿名类型 /// public static bool Exists(string sqlStr, Object param) { using (IDbConnection conn = DapperHelper.DbConnection()) { int count = conn.Query (sqlStr, param).FirstOrDefault(); return count > 0 ? true : false; } } }
调用:
#region 判断是否存在库存(不论热前还是热后) ////// 判断是否存在库存(不论热前还是热后) /// /// 流转卡号 ///public bool ExistInventory(string processCardNumber) { string sqlStr = " SELECT COUNT(1) FROM udtWip_Inventory WHERE processCardNumber=@processCardNumber "; return DapperHelper.Exists(sqlStr, new { processCardNumber = processCardNumber }); } #endregion