Ejemplo n.º 1
0
        /// <summary>
        ///     添加或者减少某个字段(支持延迟加载)
        /// </summary>
        public Task <int> AddUpAsync()
        {
            Check.NotNull(Queue.ExpBuilder.ExpAssign, "+=字段操作时,必须先执行AddUp的另一个重载版本!");

            // 加入队列
            return(QueueManger.CommitAsync(SetMap, (queue) => Context.Executeor.ExecuteAsync(queue.SqlBuilder.AddUp()), true));
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     查询多条记录(不支持延迟加载)
        /// </summary>
        /// <param name="pageSize">每页显示数量</param>
        /// <param name="pageIndex">分页索引</param>
        /// <param name="isDistinct">返回当前条件下非重复数据</param>
        /// <returns></returns>
        public virtual Task <List <TEntity> > ToListAsync(int pageSize, int pageIndex, bool isDistinct = false)
        {
            // 计算总页数
            Check.IsTure(pageIndex < 1, $"参数{nameof(pageSize)},不能小于1");
            Check.IsTure(pageSize < 1, $"参数{nameof(pageSize)},不能小于1");

            return(QueueManger.CommitAsync(SetMap, (queue) => Context.Executeor.ToListAsync <TEntity>(queue.SqlBuilder.ToList(pageSize, pageIndex, isDistinct)), true));
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     修改(支持延迟加载)
        ///     如果设置了主键ID,并且entity的ID设置了值,那么会自动将ID的值转换成条件 entity.ID == 值
        /// </summary>
        /// <param name="entity"></param>
        public Task <int> UpdateAsync(TEntity entity)
        {
            Check.IsTure(entity == null && Queue.ExpBuilder.ExpAssign == null, "更新操作时,参数不能为空!");
            // 实体类的赋值,转成表达式树
            Queue.ExpBuilder.AssignUpdate(entity);

            // 加入队列
            return(QueueManger.CommitAsync(SetMap, (queue) => Context.Executeor.ExecuteAsync(queue.SqlBuilder.Update()), true));
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     查询最小数(不支持延迟加载)
        /// </summary>
        public virtual Task <T> MinAsync <T>(Expression <Func <TEntity, T> > fieldName, T defValue = default(T)) where T : struct
        {
            if (fieldName == null)
            {
                throw new ArgumentNullException("fieldName", "查询Min操作时,fieldName参数不能为空!");
            }

            Select(fieldName);
            return(QueueManger.CommitAsync(SetMap, (queue) => Context.Executeor.GetValueAsync(queue.SqlBuilder.Min(), defValue), true));
        }
Ejemplo n.º 5
0
        /// <summary>
        ///     删除
        /// </summary>
        public Task <int> DeleteAsync()
        {
            if (SetMap.SortDelete != null)
            {
                Queue.ExpBuilder.AddAssign(SetMap.SortDelete.AssignExpression);
                return(UpdateAsync(null));
            }

            // 加入队列
            return(QueueManger.CommitAsync(SetMap, (queue) => Context.Executeor.ExecuteAsync(queue.SqlBuilder.Delete()), false));
        }
Ejemplo n.º 6
0
        /// <summary>
        ///     插入
        /// </summary>
        /// <param name="lst">实体类</param>
        public async Task <int> InsertAsync(List <TEntity> lst)
        {
            Check.NotNull(lst, "插入操作时,lst参数不能为空!");

            // 如果是MSSQLSER,则启用BulkCopy
            if (Context.Executeor.DataBase.DataType == eumDbType.SqlServer)
            {
                return(await QueueManger.CommitAsync(SetMap, async (queue) =>
                {
                    await Context.Executeor.DataBase.ExecuteSqlBulkCopyAsync(SetMap.Name, lst.ToTable());
                    return lst.Count;
                }, false));
            }

            foreach (var entity in lst)
            {
                await InsertAsync(entity);
            }
            return(lst.Count);
        }
Ejemplo n.º 7
0
        /// <summary>
        ///     插入
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="isReturnLastID">是否需要返回标识字段(如果设置的话)</param>
        public Task <int> InsertAsync(TEntity entity, bool isReturnLastID = false)
        {
            Check.NotNull(entity, "插入操作时,参数不能为空!");

            // 实体类的赋值,转成表达式树
            Queue.ExpBuilder.AssignInsert(entity);

            // 需要返回值时,则不允许延迟提交
            if (isReturnLastID && SetMap.PhysicsMap.DbGeneratedFields.Key != null)
            {
                // 赋值标识字段
                return(QueueManger.CommitAsync(SetMap, async(queue) =>
                {
                    var sourceValue = await Context.Executeor.GetValueAsync <object>(queue.SqlBuilder.InsertIdentity());
                    PropertySetCacheManger.Cache(SetMap.PhysicsMap.DbGeneratedFields.Key, entity, ConvertHelper.ConvertType(sourceValue, SetMap.PhysicsMap.DbGeneratedFields.Key.PropertyType));
                    return 1;
                }, false));
            }

            // 不返回标识字段
            return(QueueManger.CommitAsync(SetMap, (queue) => Context.Executeor.ExecuteAsync(queue.SqlBuilder.Insert()), false));
        }
Ejemplo n.º 8
0
 /// <summary>
 ///     执行存储过程
 /// </summary>
 /// <param name="entity">传入被设置好参数赋值的实体</param>
 public Task <int> ExecuteAsync(TEntity entity = null)
 {
     // 加入委托
     //var isExitsOutParam = SetMap.PhysicsMap.MapList.Any(o => o.Value.Field.IsOutParam);
     return(QueueManger.CommitAsync(SetMap, (queue) => Context.Executeor.ExecuteAsync(Queue.ProcBuilder, entity), false));
 }
Ejemplo n.º 9
0
 /// <summary>
 ///     返回多条记录
 /// </summary>
 /// <param name="entity">传入被设置好参数赋值的实体</param>
 public Task <DataTable> ToTableAsync(TEntity entity = null) => QueueManger.CommitAsync(SetMap, (queue) => Context.Executeor.ToTableAsync(Queue.ProcBuilder, entity), false);
Ejemplo n.º 10
0
 /// <summary>
 ///     返回多条记录
 /// </summary>
 /// <param name="entity">传入被设置好参数赋值的实体</param>
 public Task <List <TEntity> > ToListAsync(TEntity entity = null) => QueueManger.CommitAsync(SetMap, (queue) => Context.Executeor.ToListAsync <TEntity>(Queue.ProcBuilder, entity), false);
Ejemplo n.º 11
0
 /// <summary>
 ///     返回查询的值
 /// </summary>
 /// <param name="entity">传入被设置好参数赋值的实体</param>
 /// <param name="t">失败时返回的值</param>
 public Task <T> GetValueAsync <T>(TEntity entity = null, T t = default(T)) => QueueManger.CommitAsync(SetMap, (queue) => Context.Executeor.GetValueAsync(Queue.ProcBuilder, entity, t), false);
Ejemplo n.º 12
0
 /// <summary>
 ///     查询数量(不支持延迟加载)
 /// </summary>
 public virtual Task <int> CountAsync(bool isDistinct = false, bool isRand = false) => QueueManger.CommitAsync(SetMap, (queue) => Context.Executeor.GetValueAsync <int>(queue.SqlBuilder.Count()), true);
Ejemplo n.º 13
0
 /// <summary>
 ///     查询单条记录(不支持延迟加载)
 /// </summary>
 public virtual Task <TEntity> ToEntityAsync() => QueueManger.CommitAsync(SetMap, (queue) => Context.Executeor.ToEntityAsync <TEntity>(queue.SqlBuilder.ToEntity()), true);
Ejemplo n.º 14
0
 /// <summary> 查询多条记录(不支持延迟加载) </summary>
 /// <param name="top">限制显示的数量</param>
 /// <param name="isDistinct">返回当前条件下非重复数据</param>
 /// <param name="isRand">返回当前条件下随机的数据</param>
 public virtual Task <List <TEntity> > ToListAsync(int top = 0, bool isDistinct = false, bool isRand = false) => QueueManger.CommitAsync(SetMap, (queue) => Context.Executeor.ToListAsync <TEntity>(queue.SqlBuilder.ToList(top, isDistinct, isRand)), true);