Exemple #1
0
        /// <summary>
        /// 插入(不支持延迟加载)
        /// </summary>
        /// <param name="lst"></param>
        public void Insert(List <TEntity> lst)
        {
            if (lst == null)
            {
                throw new ArgumentNullException("lst", "插入操作时,lst参数不能为空!");
            }

            // 加入委托
            QueueManger.AppendLazy(Name, SetState, (queue) =>
            {
                // 如果是MSSQLSER,则启用BulkCopy
                if (Context.DataBase.DataType == DataBaseType.SqlServer)
                {
                    Context.DataBase.ExecuteSqlBulkCopy(Name, ConvertHelper.ToTable(lst));
                }
                else
                {
                    lst.ForEach(entity =>
                    {
                        queue.ExpBuilder.AssignInsert(entity);
                        Context.Executeor.Execute(queue.SqlBuilder.Insert());
                    });
                }
            }, !Context.IsMergeCommand, false);
        }
Exemple #2
0
 /// <summary>
 /// 删除(支持延迟加载)
 /// </summary>
 public void Delete()
 {
     if (SetState.SortDeleteAtt != null)
     {
         Queue.ExpBuilder.AddAssign(SetState.SortDeleteAtt.AssignExpression); Update(null); return;
     }
     // 加入委托
     QueueManger.AppendLazy(Name, SetState, (queue) => Context.Executeor.Execute(queue.SqlBuilder.Delete()), !Context.IsMergeCommand, false);
 }
Exemple #3
0
        /// <summary>
        /// 添加或者减少某个字段(支持延迟加载)
        /// </summary>
        public void AddUp()
        {
            if (Queue.ExpBuilder.ExpAssign == null)
            {
                throw new ArgumentNullException("ExpAssign", "+=字段操作时,必须先执行AddUp的另一个重载版本!");
            }

            // 加入委托
            QueueManger.AppendLazy(Name, SetState, (queue) => Context.Executeor.Execute(queue.SqlBuilder.AddUp()), !Context.IsMergeCommand, true);
        }
Exemple #4
0
        /// <summary>
        /// 修改(支持延迟加载)
        /// 如果设置了主键ID,并且entity的ID设置了值,那么会自动将ID的值转换成条件 entity.ID == 值
        /// </summary>
        /// <param name="entity"></param>
        public void Update(TEntity entity)
        {
            Check.IsTure(entity == null && Queue.ExpBuilder.ExpAssign == null, "更新操作时,参数不能为空!");

            // 加入委托
            QueueManger.AppendLazy(Name, SetState, (queue) =>
            {
                queue.ExpBuilder.AssignUpdate(entity);
                Context.Executeor.Execute(queue.SqlBuilder.Update());
            }, !Context.IsMergeCommand, true);
        }
        /// <summary>
        /// 实例化子类中,所有Set属性
        /// </summary>
        private void InstanceProperty()
        {
            IsMergeCommand = true;
            DbProvider     = AbsDbProvider.CreateInstance(DataBase.DataType);
            QueueManger    = new QueueManger(this);
            Executeor      = SystemConfigs.ConfigEntity.IsWriteDbLog ? new ExecuteSqlProxy(this) : new ExecuteSql(this);

            InstanceProperty(this, "TableSet`1");
            InstanceProperty(this, "TableSetCache`1");
            InstanceProperty(this, "ViewSet`1");
            InstanceProperty(this, "ViewSetCache`1");
            InstanceProperty(this, "ProcSet`1");
        }
Exemple #6
0
        /// <summary>
        /// 插入(延迟加载情况下,ID只有在SaveChange()后才能返回)
        /// </summary>
        /// <param name="entity">实体类</param>
        /// <param name="identity">返回新增的</param>
        public void Insert(TEntity entity, out int identity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity", "插入操作时,参数不能为空!");
            }

            var ident = 0;

            QueueManger.AppendLazy(Name, SetState, (queue) =>
            {
                queue.ExpBuilder.AssignInsert(entity);
                ident = Context.Executeor.GetValue <int>(queue.SqlBuilder.InsertIdentity());
            }, !Context.IsMergeCommand, false);

            identity = ident;
        }
Exemple #7
0
        /// <summary>
        /// 插入(支持延迟加载)
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="isReturnLastID">是否设置主键ID为返回的最新ID</param>
        public void Insert(TEntity entity, bool isReturnLastID = false)
        {
            Check.NotNull(entity, "插入操作时,参数不能为空!");

            // 加入委托
            QueueManger.AppendLazy(Name, SetState, (queue) =>
            {
                queue.ExpBuilder.AssignInsert(entity);
                if (!isReturnLastID)
                {
                    Context.Executeor.Execute(queue.SqlBuilder.Insert());
                }
                else
                {
                    // 返回主键ID
                    var ident = Context.Executeor.GetValue <int>(queue.SqlBuilder.InsertIdentity());
                    // 设置主键ID
                    if (SetState.FieldMap.PrimaryState.Key != null)
                    {
                        CacheManger.SetValue(SetState.FieldMap.PrimaryState.Key, entity, ident);
                    }
                }
            }, !Context.IsMergeCommand, false);
        }