Beispiel #1
0
 /// <summary>
 /// 执行选择单个值的参数化SQL。
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="sql"></param>
 /// <param name="parameters"></param>
 /// <param name="commandType"></param>
 /// <returns></returns>
 public T ExecuteScalar <T>(string sql, DynamicParameters parameters = null, CommandType?commandType = null)
 {
     if (CurrentTransaction != null)
     {
         return(DbExecProxy <T>((param) => CurrentConnection.ExecuteScalar <T>(sql, param, CurrentTransaction, CommandTimeout, commandType), sql, parameters));
     }
     using var connection = GetDbConnection(DataSourceEnum.SLAVE);
     return(DbExecProxy <T>((param) => connection.ExecuteScalar <T>(sql, param, CurrentTransaction, CommandTimeout, commandType), sql, parameters));
 }
Beispiel #2
0
        /// <summary>
        /// 条件判断是否存在
        /// </summary>
        /// <returns>是否存在</returns>
        /// <param name="predicate">判断条件委托</param>
        public bool Exist <T>(Expression <Func <T, bool> > predicate = null)
            where T : ModelBase
        {
            string      tableName   = GetTableName <T>();
            QueryResult queryResult = DynamicQuery.GetDynamicQuery(tableName, predicate);

            object result = CurrentConnection.ExecuteScalar(queryResult.Sql, (object)queryResult.Param, CurrentTransaction);

            return(result != null);
        }