public async Task <T> GetValueAsync <TEntity, T>(ProcBuilder procBuilder, TEntity entity, T defValue = default(T)) where TEntity : class, new()
 {
     try { return(await _dbExecutor.GetValueAsync(procBuilder, entity, defValue)); }
     catch (Exception ex)
     {
         WriteException(ex, procBuilder);
         throw;
     }
 }
 public DataTable ToTable <TEntity>(ProcBuilder procBuilder, TEntity entity) where TEntity : class, new()
 {
     try { return(_dbExecutor.ToTable(procBuilder, entity)); }
     catch (Exception ex)
     {
         WriteException(ex, procBuilder);
         throw;
     }
 }
 public async Task <DataTable> ToTableAsync <TEntity>(ProcBuilder procBuilder, TEntity entity) where TEntity : class, new()
 {
     try { return(await _dbExecutor.ToTableAsync(procBuilder, entity)); }
     catch (Exception ex)
     {
         WriteException(ex, procBuilder);
         throw;
     }
 }
예제 #4
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);
        }
예제 #5
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);
        }
예제 #6
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);
        }
예제 #7
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));
        }
예제 #8
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);
        }
예제 #9
0
        /// <summary>
        ///     计算执行时间
        /// </summary>
        private TReturn SpeedTest <TReturn>(ProcBuilder procBuilder, Func <TReturn> func)
        {
            var timer = new Stopwatch();

            timer.Start();
            var val = func();

            timer.Stop();

            new SqlRunLog(procBuilder.Name, CommandType.StoredProcedure, "", procBuilder.Param, timer.ElapsedMilliseconds).Write();
            return(val);
        }
예제 #10
0
 /// <summary>
 ///     释放资源
 /// </summary>
 /// <param name="disposing">是否释放托管资源</param>
 private void Dispose(bool disposing)
 {
     //释放托管资源
     if (disposing)
     {
         Context      = null;
         Map          = null;
         _expBuilder  = null;
         _sqlBuilder  = null;
         _procBuilder = null;
         LazyAct      = null;
     }
 }
 public T GetValue <TEntity, T>(ProcBuilder procBuilder, TEntity entity, T defValue = default(T))
     where TEntity : class, new()
 {
     return(SpeedTest("GetValue", procBuilder.Name, CommandType.StoredProcedure, null, procBuilder.Param, () => _dbExecutor.GetValue(procBuilder, entity, defValue)));
 }
 public List <TEntity> ToList <TEntity>(ProcBuilder procBuilder, TEntity entity) where TEntity : class, new()
 {
     return(SpeedTest("ToList", procBuilder.Name, CommandType.StoredProcedure, null, procBuilder.Param, () => _dbExecutor.ToList(procBuilder, entity)));
 }
 /// <summary> 写入日志 </summary>
 private void WriteException(Exception ex, ProcBuilder procBuilder)
 {
     new SqlErrorLog(ex, procBuilder.Name, CommandType.StoredProcedure, "", procBuilder.Param ?? new List <DbParameter>()).Write();
 }
 public Task <List <TEntity> > ToListAsync <TEntity>(ProcBuilder procBuilder, TEntity entity)
     where TEntity : class, new()
 {
     return(SpeedTest("ToListAsync", procBuilder.Name, CommandType.StoredProcedure, null, procBuilder.Param, async() => await _dbExecutor.ToListAsync(procBuilder, entity)));
 }
예제 #15
0
 public Task <T> GetValueAsync <TEntity, T>(ProcBuilder procBuilder, TEntity entity, T defValue = default(T)) where TEntity : class, new() => SpeedTest(procBuilder, async() => await _dbExecutor.GetValueAsync(procBuilder, entity, defValue));
예제 #16
0
 public T GetValue <TEntity, T>(ProcBuilder procBuilder, TEntity entity, T defValue             = default(T)) where TEntity : class, new() => SpeedTest(procBuilder, () => _dbExecutor.GetValue(procBuilder, entity, defValue));
예제 #17
0
 public Task <TEntity> ToEntityAsync <TEntity>(ProcBuilder procBuilder, TEntity entity) where TEntity : class, new() => SpeedTest(procBuilder, async() => await _dbExecutor.ToEntityAsync(procBuilder, entity));
예제 #18
0
 public TEntity ToEntity <TEntity>(ProcBuilder procBuilder, TEntity entity) where TEntity : class, new() => SpeedTest(procBuilder, () => _dbExecutor.ToEntity(procBuilder, entity));
예제 #19
0
 public DataTable ToTable <TEntity>(ProcBuilder procBuilder, TEntity entity) where TEntity : class, new() => SpeedTest(procBuilder, () => _dbExecutor.ToTable(procBuilder, entity));
예제 #20
0
 public int Execute <TEntity>(ProcBuilder procBuilder, TEntity entity) where TEntity : class, new() => SpeedTest(procBuilder, () => _dbExecutor.Execute(procBuilder, entity));
 public Task <T> GetValueAsync <TEntity, T>(ProcBuilder procBuilder, TEntity entity, T defValue = default(T)) where TEntity : class, new()
 {
     return(SpeedTest("GetValueAsync", procBuilder.Name, CommandType.StoredProcedure, null, procBuilder.Param, async() => await _dbExecutor.GetValueAsync(procBuilder, entity, defValue)));
 }