static DbTableSegment CreateTableExpression(DbTable table, string alias) { DbTableExpression tableExp = new DbTableExpression(table); DbTableSegment tableSeg = new DbTableSegment(tableExp, alias); return(tableSeg); }
static DbTableSegment CreateTableSegment(DbTable table, string alias, LockType @lock) { DbTableExpression tableExp = new DbTableExpression(table); DbTableSegment tableSeg = new DbTableSegment(tableExp, alias, @lock); return(tableSeg); }
ComplexObjectModel GenComplexObjectModel(ComplexPropertyDescriptor navigationDescriptor, NavigationNode navigationNode, QueryModel queryModel) { TypeDescriptor navigationTypeDescriptor = EntityTypeContainer.GetDescriptor(navigationDescriptor.PropertyType); DbTable dbTable = navigationTypeDescriptor.Table; DbTableExpression tableExp = new DbTableExpression(dbTable); string alias = queryModel.GenerateUniqueTableAlias(dbTable.Name); DbTableSegment joinTableSeg = new DbTableSegment(tableExp, alias, queryModel.FromTable.Table.Lock); DbTable aliasTable = new DbTable(alias); ComplexObjectModel navigationObjectModel = navigationTypeDescriptor.GenObjectModel(aliasTable); navigationObjectModel.NullChecking = navigationObjectModel.PrimaryKey; PrimitivePropertyDescriptor foreignKeyPropertyDescriptor = navigationDescriptor.ForeignKeyProperty; DbExpression foreignKeyColumn = this.GetPrimitiveMember(foreignKeyPropertyDescriptor.Property); DbExpression joinCondition = DbExpression.Equal(foreignKeyColumn, navigationObjectModel.PrimaryKey); DbJoinTableExpression joinTableExp = new DbJoinTableExpression(foreignKeyPropertyDescriptor.IsNullable ? DbJoinType.LeftJoin : DbJoinType.InnerJoin, joinTableSeg, joinCondition); this.DependentTable.JoinTables.Add(joinTableExp); navigationObjectModel.DependentTable = joinTableExp; DbExpression condition = this.ParseCondition(navigationNode.Condition, navigationObjectModel, queryModel.ScopeTables); //AndWhere的条件放到join条件里去 joinTableExp.AppendCondition(condition); navigationObjectModel.Filter = this.ParseCondition(navigationNode.Filter, navigationObjectModel, queryModel.ScopeTables); //queryModel.Filters.Add(navigationObjectModel.Filter); return(navigationObjectModel); }
static DbFromTableExpression CreateRootTable(DbTable table, string alias, LockType lockType) { DbTableExpression tableExp = new DbTableExpression(table); DbTableSegment tableSeg = new DbTableSegment(tableExp, alias, lockType); var fromTableExp = new DbFromTableExpression(tableSeg); return fromTableExp; }
static DbFromTableExpression CreateRootTable(DbTable table, string alias) { DbTableExpression tableExp = new DbTableExpression(table); DbTableSegment tableSeg = new DbTableSegment(tableExp, alias); var fromTableExp = new DbFromTableExpression(tableSeg); return(fromTableExp); }
public override DbExpression Visit(DbTableExpression exp) { if (exp.Table.Schema != null) { this.QuoteName(exp.Table.Schema); this._sqlBuilder.Append("."); } this.QuoteName(exp.Table.Name); return(exp); }
ComplexObjectModel GenCollectionElementObjectModel(TypeDescriptor elementTypeDescriptor, NavigationNode navigationNode, QueryModel queryModel) { DbTable dbTable = elementTypeDescriptor.Table; DbTableExpression tableExp = new DbTableExpression(dbTable); string alias = queryModel.GenerateUniqueTableAlias(dbTable.Name); DbTableSegment joinTableSeg = new DbTableSegment(tableExp, alias, queryModel.FromTable.Table.Lock); DbTable aliasTable = new DbTable(alias); ComplexObjectModel elementObjectModel = elementTypeDescriptor.GenObjectModel(aliasTable); elementObjectModel.NullChecking = elementObjectModel.PrimaryKey; ComplexPropertyDescriptor navigationDescriptor = elementTypeDescriptor.ComplexPropertyDescriptors.Where(a => a.PropertyType == this.ObjectType).FirstOrDefault(); if (navigationDescriptor == null) { throw new ChloeException($"You have to define a navigation property which type is '{this.ObjectType.FullName}' on class '{elementTypeDescriptor.Definition.Type.FullName}'."); } DbExpression elementForeignKeyColumn = elementObjectModel.GetPrimitiveMember(navigationDescriptor.ForeignKeyProperty.Property); DbExpression joinCondition = DbExpression.Equal(this.PrimaryKey, elementForeignKeyColumn); DbJoinTableExpression joinTableExp = new DbJoinTableExpression(DbJoinType.LeftJoin, joinTableSeg, joinCondition); this.DependentTable.JoinTables.Add(joinTableExp); elementObjectModel.DependentTable = joinTableExp; var condition = this.ParseCondition(navigationNode.Condition, elementObjectModel, queryModel.ScopeTables); //AndWhere的条件放到join条件里去 joinTableExp.AppendCondition(condition); elementObjectModel.Filter = this.ParseCondition(navigationNode.Filter, elementObjectModel, queryModel.ScopeTables); bool orderByPrimaryKeyExists = queryModel.Orderings.Where(a => a.Expression == this.PrimaryKey).Any(); if (!orderByPrimaryKeyExists) { //结果集分组 DbOrdering ordering = new DbOrdering(this.PrimaryKey, DbOrderType.Asc); queryModel.Orderings.Add(ordering); } //queryModel.Filters.Add(elementObjectModel.Filter); return(elementObjectModel); }
protected override Expression VisitSource(Expression source) { bool saveIsNested = this.isNested; this.isNested = true; switch ((DbExpressionType)source.NodeType) { case DbExpressionType.Table: DbTableExpression table = (DbTableExpression)source; this.WriteTableName(table.Name); if (!this.HideTableAliases) { this.Write(" AS "); this.WriteAliasName(GetAliasName(table.Alias)); } break; case DbExpressionType.Select: DbSelectExpression select = (DbSelectExpression)source; this.Write("("); this.WriteLine(Indentation.Inner); this.Visit(select); this.WriteLine(Indentation.Same); this.Write(")"); this.Write(" AS "); this.WriteAliasName(GetAliasName(select.Alias)); this.Indent(Indentation.Outer); break; case DbExpressionType.Join: this.VisitJoin((DbJoinExpression)source); break; default: throw new InvalidOperationException("Select source is not valid type"); } this.isNested = saveIsNested; return(source); }
public override DbExpression Visit(DbTableExpression exp) { this.AppendTable(exp.Table); return(exp); }
public override DbExpression Visit(DbTableExpression exp) { this.QuoteName(exp.Table.Name); return(exp); }
public static bool AreEqual(DbTableExpression exp1, DbTableExpression exp2) { return(exp1.Table.Name == exp2.Table.Name); }
public override DbExpression Visit(DbTableExpression exp) { return(exp); }
public override DbExpression Visit(DbTableExpression exp) { return(exp.Accept(this._generator)); }
public abstract T Visit(DbTableExpression exp);
public static bool ExpressionEquals(DbTableExpression exp1, DbTableExpression exp2) { return exp1.Table.Name == exp2.Table.Name; }