Ejemplo n.º 1
0
        /// <summary>
        ///     返回影响行数
        /// </summary>
        /// <typeparam name="TEntity">实体类</typeparam>
        /// <param name="procBuilder">SQL语句与参数</param>
        /// <param name="entity">实体类</param>
        public async Task <int> ExecuteAsync <TEntity>(ProcBuilder procBuilder, TEntity entity) where TEntity : class, new()
        {
            // 生成SQL 输入、输出参数化
            var sqlParam = procBuilder.InitParam(entity);
            var param    = sqlParam.Param?.ToArray();
            var value    = await DataBase.ExecuteNonQueryAsync(CommandType.StoredProcedure, sqlParam.Name, param);

            procBuilder.SetParamToEntity(entity);
            return(value);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     查询单个字段值
        /// </summary>
        /// <typeparam name="T">返回值类型</typeparam>
        /// <typeparam name="TEntity">实体类型</typeparam>
        /// <param name="procBuilder">存储过程生成器</param>
        /// <param name="entity">实体</param>
        /// <param name="defValue">默认值</param>
        public async Task <T> GetValueAsync <TEntity, T>(ProcBuilder procBuilder, TEntity entity, T defValue = default(T)) where TEntity : class, new()
        {
            // 生成SQL 输入、输出参数化
            var sqlParam = procBuilder.InitParam(entity);
            var param    = sqlParam.Param?.ToArray();
            var value    = await DataBase.ExecuteScalarAsync(CommandType.StoredProcedure, sqlParam.Name, param);

            procBuilder.SetParamToEntity(entity);
            return(ConvertHelper.ConvertType(value, defValue));
        }
Ejemplo n.º 3
0
        public async Task <List <TEntity> > ToListAsync <TEntity>(ProcBuilder procBuilder, TEntity entity) where TEntity : class, new()
        {
            // 生成SQL 输入、输出参数化
            var sqlParam = procBuilder.InitParam(entity);
            var param    = sqlParam.Param?.ToArray();
            var value    = SqlExtend.ToList <TEntity>(await DataBase.GetReaderAsync(CommandType.StoredProcedure, sqlParam.Name, param));

            procBuilder.SetParamToEntity(entity);
            return(value);
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     返回影响行数
        /// </summary>
        /// <typeparam name="TEntity">实体类</typeparam>
        /// <param name="procBuilder">SQL语句与参数</param>
        /// <param name="entity">实体类</param>
        public DataTable ToTable <TEntity>(ProcBuilder procBuilder, TEntity entity) where TEntity : class, new()
        {
            // 生成SQL 输入、输出参数化
            var sqlParam = procBuilder.InitParam(entity);
            var param    = sqlParam.Param?.ToArray();
            var value    = DataBase.GetDataTable(CommandType.StoredProcedure, sqlParam.Name, param);

            procBuilder.SetParamToEntity(entity);
            return(value);
        }
Ejemplo n.º 5
0
        /// <summary>
        ///     返回影响行数
        /// </summary>
        /// <typeparam name="TEntity">实体类</typeparam>
        /// <param name="procBuilder">SQL语句与参数</param>
        /// <param name="entity">实体类</param>
        public async Task <TEntity> ToEntityAsync <TEntity>(ProcBuilder procBuilder, TEntity entity) where TEntity : class, new()
        {
            // 生成SQL 输入、输出参数化
            var     sqlParam = procBuilder.InitParam(entity);
            var     param    = sqlParam.Param?.ToArray();
            TEntity t;

            using (var reader = await DataBase.GetReaderAsync(CommandType.StoredProcedure, sqlParam.Name, param)) { t = reader.ToEntity <TEntity>(); }
            DataBase.Close(false);
            procBuilder.SetParamToEntity(entity);
            return(t);
        }