private void ValidateActionStateChange(DbQueryAction nextAction) { if (!CanChangeActionStateTo(nextAction)) { throw new InvalidOperationException($"不能从当前状态【{m_pLastAction}】变更到【{nextAction}】"); } }
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())); }
public void SetHaving(LambdaExpression havingExpression) { ValidateActionStateChange(DbQueryAction.SetHaving); m_pLastAction = DbQueryAction.SetHaving; this.HavingExpression = havingExpression; }
public void SetOrderBy(LambdaExpression orderByExpression) { ValidateActionStateChange(DbQueryAction.SetOrderBy); m_pLastAction = DbQueryAction.SetOrderBy; this.OrderByExpressions.Add(orderByExpression); }
public void SetWhere(LambdaExpression whereExpression) { ValidateActionStateChange(DbQueryAction.SetWhere); m_pLastAction = DbQueryAction.SetWhere; this.WhereExpressions.Add(whereExpression); }
public void SetGroupBy(LambdaExpression groupByExpression) { ValidateActionStateChange(DbQueryAction.SetGroupBy); m_pLastAction = DbQueryAction.SetGroupBy; this.GroupByExpression = groupByExpression; }
public void SetFrom(DbQueryContext queryContext) { ValidateActionStateChange(DbQueryAction.SetFrom); m_pLastAction = DbQueryAction.SetFrom; this.FromTables.Add(new TableInfo(queryContext, this.Session.CreateTempTableName())); }
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)); }
public void SetSelect(LambdaExpression selectExpression) { ValidateActionStateChange(DbQueryAction.SetSelect); m_pLastAction = DbQueryAction.SetSelect; this.SelectExpression = selectExpression; }
public void SetPaging(uint offset, uint count) { ValidateActionStateChange(DbQueryAction.SetPaging); m_pLastAction = DbQueryAction.SetPaging; this.PagingInfo = new PagingInfo(offset, count); }
public void SetDistinct() { ValidateActionStateChange(DbQueryAction.SetDistinct); m_pLastAction = DbQueryAction.SetDistinct; this.Distinct = true; }
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)); }
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)); }
internal DbQueryContext SnapshotForAction(DbQueryAction action) { if (!this.CanChangeActionStateTo(action)) { var newContext = new DbQueryContext(this.Session); newContext.SetFrom(CloneContext()); return(newContext); } return(CloneContext()); }
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); } } }