Пример #1
0
        /// <summary>
        /// 删除数据表中满足指定条件的数据.
        /// </summary>
        /// <param name="func">用于创建删除条件.</param>
        /// <exception cref="Exception">当未指定更新条件或删除过程产生错误时引发此异常.</exception>
        /// <returns>返回受影响记录数.</returns>
        public int Delete(Func <TEntityAgent, object[]> func)
        {
            if (func == null)
            {
                throw new Exception("在不指定条件的情况下将会删除整个数据表中的所有数据,该操作已被禁止.");
            }
            EntityTableAttribute tableAttribute = GetTableAttribute();
            TEntityAgent         agent          = new TEntityAgent();

            agent.TableContext = this;
            object[] conditions = func(agent);
            int      result     = 0;

            if (BatchProccesser == null)
            {
                QuickDataChanger DC = new QuickDataChanger(Writer);
                DC.Conditions.AddRange(conditions);
                result = DC.Delete(tableAttribute.TableName);
                if (result == -1)
                {
                    throw new Exception(Writer.DBA.Error.Message);
                }
            }
            else
            {
                DbCommandBuilder cb = new DbCommandBuilder();
                cb.Delete(tableAttribute.TableName).Where(conditions);
                result = BatchProccesser.Commander.ExecuteNonQuery(cb);
            }
            return(result);
        }
Пример #2
0
        /// <summary>
        /// 从删除。
        /// </summary>
        /// <param name="TableName">要从中删除数据的表(条件请指定 Conditions 属性)。</param>
        /// <returns></returns>
        public int Delete(string TableName)
        {
            DbCommandBuilder Command = new DbCommandBuilder();

            if (Conditions != null)
            {
                Command.Delete(fm.Table(TableName)).Where(Conditions.ToArray());
            }
            else
            {
                Command.Delete(fm.Table(TableName));
            }
            if (Trans == null)
            {
                return(Engine.DBA.ExecuteNoneQuery(Command));
            }
            else
            {
                return(Trans.DBA.ExecuteNoneQuery(Command));
            }
        }
Пример #3
0
        /// <summary>
        /// 判断并构建指定行被指示的提交命令。
        /// </summary>
        /// <param name="Row">被提交的行。</param>
        /// <param name="rowSubmission">对该行的处理指示。</param>
        /// <returns></returns>
        private DbCommandBuilder DataRowSubmissionCommand(DataRow Row, DataRowSubmission rowSubmission)
        {
            if (rowSubmission == null)
            {
                return(null);
            }
            // 开始构建命令。
            DbCommandBuilder Command = new DbCommandBuilder();

            switch (rowSubmission.Submission)
            {
            case QuickDataChangerSubmission.Delete:
                if (rowSubmission.Conditions != null && rowSubmission.Conditions.Count > 0)
                {
                    Command.Delete(Row.Table.TableName).Where(rowSubmission.Conditions.ToArray());
                }
                break;

            case QuickDataChangerSubmission.Update:
                if (rowSubmission.Conditions != null && rowSubmission.Conditions.Count > 0)
                {
                    List <IDescription> expressions = new List <IDescription>();
                    foreach (DataColumn c in Row.Table.Columns)
                    {
                        if (!NotInsertFieldsContains(rowSubmission, c.ColumnName))
                        {
                            expressions.Add(td.Field(c.ColumnName) == Row[c.ColumnName]);
                        }
                    }
                    Command.Update(Row.Table.TableName).Set(expressions.ToArray()).Where(rowSubmission.Conditions.ToArray());
                }
                break;

            case QuickDataChangerSubmission.Insert:
                List <FieldDescription> Fields = new List <FieldDescription>();
                List <object>           Values = new List <object>();
                foreach (DataColumn c in Row.Table.Columns)
                {
                    if (!NotInsertFieldsContains(rowSubmission, c.ColumnName))
                    {
                        Fields.Add(td.Field(c.ColumnName));
                        Values.Add(Row[c.ColumnName]);
                    }
                }
                Command.Insert(fm.Table(Row.Table.TableName), Fields.ToArray()).Values(Values.ToArray());
                break;

            default:
                break;
            }
            return(Command);
        }
Пример #4
0
        public bool DeleteData(object[] filters)
        {
            int result = -1;

            using (DBTransactionController Trans = DataEngine.CurrentEngine.BeginTrans())
            {
                DbCommandBuilder Command = new DbCommandBuilder();
                Command.Delete(fm.Table(TABLE_NAME)).Where(td.Field("TestId").In(filters));
                result = Trans.DBA.ExecuteNoneQuery(Command);
                Trans.Commit();
            }
            return(result > 0);
        }