示例#1
0
 private void ValidateActionStateChange(DbQueryAction nextAction)
 {
     if (!CanChangeActionStateTo(nextAction))
     {
         throw new InvalidOperationException($"不能从当前状态【{m_pLastAction}】变更到【{nextAction}】");
     }
 }
示例#2
0
        public void AddUnionAll <TEntity>(DbQuerySet <TEntity> querySet)
        {
            ValidateActionStateChange(DbQueryAction.SetUnion);

            m_pLastAction = DbQueryAction.SetUnion;
            this.UnionTargets.Add(new UnionTarget(UnionMode.UnionAll, querySet.QueryContext, this.Session.CreateTempTableName()));
        }
示例#3
0
        public void SetHaving(LambdaExpression havingExpression)
        {
            ValidateActionStateChange(DbQueryAction.SetHaving);

            m_pLastAction         = DbQueryAction.SetHaving;
            this.HavingExpression = havingExpression;
        }
示例#4
0
        public void SetOrderBy(LambdaExpression orderByExpression)
        {
            ValidateActionStateChange(DbQueryAction.SetOrderBy);

            m_pLastAction = DbQueryAction.SetOrderBy;
            this.OrderByExpressions.Add(orderByExpression);
        }
示例#5
0
        public void SetWhere(LambdaExpression whereExpression)
        {
            ValidateActionStateChange(DbQueryAction.SetWhere);

            m_pLastAction = DbQueryAction.SetWhere;
            this.WhereExpressions.Add(whereExpression);
        }
示例#6
0
        public void SetGroupBy(LambdaExpression groupByExpression)
        {
            ValidateActionStateChange(DbQueryAction.SetGroupBy);

            m_pLastAction          = DbQueryAction.SetGroupBy;
            this.GroupByExpression = groupByExpression;
        }
示例#7
0
        public void SetFrom(DbQueryContext queryContext)
        {
            ValidateActionStateChange(DbQueryAction.SetFrom);

            m_pLastAction = DbQueryAction.SetFrom;
            this.FromTables.Add(new TableInfo(queryContext, this.Session.CreateTempTableName()));
        }
示例#8
0
        public void SetFrom <TEntity>(DbTable <TEntity> table)
        {
            ValidateActionStateChange(DbQueryAction.SetFrom);

            m_pLastAction = DbQueryAction.SetFrom;
            this.FromTables.Add(new TableInfo(table.TableName, this.Session.CreateTempTableName(), typeof(TEntity), table.Schema));
        }
示例#9
0
        public void SetSelect(LambdaExpression selectExpression)
        {
            ValidateActionStateChange(DbQueryAction.SetSelect);

            m_pLastAction         = DbQueryAction.SetSelect;
            this.SelectExpression = selectExpression;
        }
示例#10
0
        public void SetPaging(uint offset, uint count)
        {
            ValidateActionStateChange(DbQueryAction.SetPaging);

            m_pLastAction   = DbQueryAction.SetPaging;
            this.PagingInfo = new PagingInfo(offset, count);
        }
示例#11
0
        public void SetDistinct()
        {
            ValidateActionStateChange(DbQueryAction.SetDistinct);

            m_pLastAction = DbQueryAction.SetDistinct;
            this.Distinct = true;
        }
示例#12
0
        public void AddLeftJoin <TJoin>(DbQuerySet <TJoin> querySet, LambdaExpression onExpression)
        {
            ValidateActionStateChange(DbQueryAction.SetJoin);

            m_pLastAction = DbQueryAction.SetJoin;
            this.FromTables.Add(new TableInfo(querySet.QueryContext, this.Session.CreateTempTableName()));
            this.JoinTargets.Add(new JoinTarget(JoinMode.LeftJoin, this.FromTables.Last(), onExpression));
        }
示例#13
0
        public void AddLeftJoin <TJoin>(DbTable <TJoin> table, LambdaExpression onExpression)
        {
            ValidateActionStateChange(DbQueryAction.SetJoin);

            m_pLastAction = DbQueryAction.SetJoin;
            this.FromTables.Add(new TableInfo(table.TableName, this.Session.CreateTempTableName(), typeof(TJoin), table.Schema));
            this.JoinTargets.Add(new JoinTarget(JoinMode.LeftJoin, this.FromTables.Last(), onExpression));
        }
示例#14
0
        internal DbQueryContext SnapshotForAction(DbQueryAction action)
        {
            if (!this.CanChangeActionStateTo(action))
            {
                var newContext = new DbQueryContext(this.Session);
                newContext.SetFrom(CloneContext());

                return(newContext);
            }

            return(CloneContext());
        }
示例#15
0
        private bool CanChangeActionStateTo(DbQueryAction nextAction)
        {
            if (nextAction == DbQueryAction.None)
            {
                throw new ArgumentException($"参数错误:查询上下文状态错误【{nextAction}】");
            }


            switch (m_pLastAction)
            {
            case DbQueryAction.SetFrom:
            {
                if (nextAction == DbQueryAction.SetJoin ||
                    nextAction == DbQueryAction.SetWhere ||
                    nextAction == DbQueryAction.SetGroupBy ||
                    nextAction == DbQueryAction.SetOrderBy ||
                    nextAction == DbQueryAction.SetSelect ||
                    nextAction == DbQueryAction.SetDistinct ||
                    nextAction == DbQueryAction.SetUnion)
                {
                    return(true);
                }

                return(false);
            }

            case DbQueryAction.SetJoin:
            {
                if (nextAction == DbQueryAction.SetJoin ||
                    nextAction == DbQueryAction.SetWhere ||
                    nextAction == DbQueryAction.SetGroupBy ||
                    nextAction == DbQueryAction.SetOrderBy ||
                    nextAction == DbQueryAction.SetSelect ||
                    nextAction == DbQueryAction.SetDistinct)
                {
                    return(true);
                }

                return(false);
            }

            case DbQueryAction.SetWhere:
            {
                if (nextAction == DbQueryAction.SetWhere ||
                    nextAction == DbQueryAction.SetGroupBy ||
                    nextAction == DbQueryAction.SetOrderBy ||
                    nextAction == DbQueryAction.SetSelect ||
                    nextAction == DbQueryAction.SetDistinct)
                {
                    return(true);
                }

                if (nextAction == DbQueryAction.SetUnion &&
                    JoinTargets.Count == 0)
                {
                    return(true);
                }

                return(false);
            }

            case DbQueryAction.SetGroupBy:
            {
                if (nextAction == DbQueryAction.SetHaving ||
                    nextAction == DbQueryAction.SetOrderBy ||
                    nextAction == DbQueryAction.SetSelect ||
                    nextAction == DbQueryAction.SetDistinct)
                {
                    return(true);
                }

                return(false);
            }

            case DbQueryAction.SetHaving:
            {
                if (nextAction == DbQueryAction.SetOrderBy ||
                    nextAction == DbQueryAction.SetSelect ||
                    nextAction == DbQueryAction.SetDistinct)
                {
                    return(true);
                }

                return(false);
            }

            case DbQueryAction.SetOrderBy:
            {
                if (nextAction == DbQueryAction.SetOrderBy ||
                    nextAction == DbQueryAction.SetPaging ||
                    nextAction == DbQueryAction.SetSelect ||
                    nextAction == DbQueryAction.SetDistinct)
                {
                    return(true);
                }

                return(false);
            }

            case DbQueryAction.SetPaging:
            {
                if (nextAction == DbQueryAction.SetSelect ||
                    nextAction == DbQueryAction.SetDistinct)
                {
                    return(true);
                }

                return(false);
            }

            case DbQueryAction.SetSelect:
            {
                if (nextAction == DbQueryAction.SetDistinct ||
                    nextAction == DbQueryAction.SetUnion)
                {
                    return(true);
                }

                return(false);
            }

            case DbQueryAction.SetDistinct:
            {
                if (nextAction == DbQueryAction.SetUnion)
                {
                    return(true);
                }

                return(false);
            }

            case DbQueryAction.SetUnion:
            {
                if (nextAction == DbQueryAction.SetUnion ||
                    nextAction == DbQueryAction.SetOrderBy)
                {
                    return(true);
                }

                return(false);
            }

            default:
            {
                if (nextAction == DbQueryAction.SetFrom)
                {
                    return(true);
                }

                return(false);
            }
            }
        }