internal void AddColumn(ColumnFragment column, Scope scope) { InputFragment input = scope.FindInputFromProperties(column.PropertyFragment); column.TableName = input.Name; // then we rename the column if necessary if (columnHash.ContainsKey(column.ColumnName.ToUpper())) { column.ColumnAlias = MakeColumnNameUnique(column.ColumnName); columnHash.Add(column.ColumnAlias, column); } else { if (!string.IsNullOrEmpty(column.ColumnAlias)) { columnHash.Add(column.ColumnAlias.ToUpper(), column); } else { columnHash.Add(column.ColumnName.ToUpper(), column); } } Columns.Add(column); }
void AddDefaultColumns(Scope scope) { if (columnHash == null) { columnHash = new Dictionary <string, ColumnFragment>(); } List <ColumnFragment> columns = GetDefaultColumnsForFragment(From); foreach (ColumnFragment column in columns) { // first we need to set the input for this column InputFragment input = scope.FindInputFromProperties(column.PropertyFragment); column.TableName = input.Name; // then we rename the column if necessary if (columnHash.ContainsKey(column.ColumnName)) { column.ColumnAlias = MakeColumnNameUnique(column.ColumnName); columnHash.Add(column.ColumnAlias, column); } else { columnHash.Add(column.ColumnName, column); } Columns.Add(column); } }
public override SqlFragment Visit(DbPropertyExpression expression) { propertyLevel++; PropertyFragment fragment = expression.Instance.Accept(this) as PropertyFragment; fragment.Properties.Add(expression.Property.Name); propertyLevel--; // if we are not at the top level property then just return if (propertyLevel > 0) { return(fragment); } ColumnFragment column = new ColumnFragment(null, fragment.LastProperty); column.PropertyFragment = fragment; InputFragment input = scope.FindInputFromProperties(fragment); if (input != null) { column.TableName = input.Name; } // now we need to check if our column name was possibly renamed if (input is TableFragment) { return(column); } SelectStatement select = input as SelectStatement; UnionFragment union = input as UnionFragment; if (select != null) { select.HasDifferentNameForColumn(column); } else if (union != null) { union.HasDifferentNameForColumn(column); } // input is a table, selectstatement, or unionstatement return(column); }
void AddDefaultColumns(Scope scope) { if (columnHash == null) { columnHash = new Dictionary <string, ColumnFragment>(); } List <ColumnFragment> columns = GetDefaultColumnsForFragment(From); bool Exists = false; if (From is TableFragment && scope.GetFragment((From as TableFragment).Table) == null) { scope.Add((From as TableFragment).Table, From); Exists = true; } foreach (ColumnFragment column in columns) { // first we need to set the input for this column InputFragment input = scope.FindInputFromProperties(column.PropertyFragment); column.TableName = input.Name; // then we rename the column if necessary if (columnHash.ContainsKey(column.ColumnName.ToUpper())) { column.ColumnAlias = MakeColumnNameUnique(column.ColumnName); columnHash.Add(column.ColumnAlias, column); } else { columnHash.Add(column.ColumnName.ToUpper(), column); } Columns.Add(column); } if (From is TableFragment && Exists) { scope.Remove((From as TableFragment).Table, From); } }
void AddDefaultColumns(Scope scope) { if (columnHash == null) columnHash = new Dictionary<string, ColumnFragment>(); List<ColumnFragment> columns = GetDefaultColumnsForFragment(From); bool Exists = false; if (From is TableFragment && scope.GetFragment((From as TableFragment).Table) == null) { scope.Add((From as TableFragment).Table, From); Exists = true; } foreach (ColumnFragment column in columns) { // first we need to set the input for this column InputFragment input = scope.FindInputFromProperties(column.PropertyFragment); column.TableName = input.Name; // then we rename the column if necessary if (columnHash.ContainsKey(column.ColumnName.ToUpper())) { column.ColumnAlias = MakeColumnNameUnique(column.ColumnName); columnHash.Add(column.ColumnAlias, column); } else columnHash.Add(column.ColumnName.ToUpper(), column); Columns.Add(column); } if (From is TableFragment && Exists) { scope.Remove(From); } }
internal void AddColumn(ColumnFragment column, Scope scope) { InputFragment input = scope.FindInputFromProperties(column.PropertyFragment); column.TableName = input.Name; // then we rename the column if necessary if (columnHash.ContainsKey(column.ColumnName.ToUpper())) { column.ColumnAlias = MakeColumnNameUnique(column.ColumnName); columnHash.Add(column.ColumnAlias, column); } else { if( !string.IsNullOrEmpty(column.ColumnAlias) ) columnHash.Add(column.ColumnAlias.ToUpper(), column); else columnHash.Add(column.ColumnName.ToUpper(), column); } Columns.Add(column); }
void AddDefaultColumns(Scope scope) { if (columnHash == null) columnHash = new Dictionary<string, ColumnFragment>(); List<ColumnFragment> columns = GetDefaultColumnsForFragment(From); foreach (ColumnFragment column in columns) { // first we need to set the input for this column InputFragment input = scope.FindInputFromProperties(column.PropertyFragment); column.TableName = input.Name; // then we rename the column if necessary if (columnHash.ContainsKey(column.ColumnName)) { column.ColumnAlias = MakeColumnNameUnique(column.ColumnName); columnHash.Add(column.ColumnAlias, column); } else columnHash.Add(column.ColumnName, column); Columns.Add(column); } }
public override SqlFragment Visit(DbPropertyExpression expression) { propertyLevel++; PropertyFragment fragment = expression.Instance.Accept(this) as PropertyFragment; fragment.Properties.Add(expression.Property.Name); propertyLevel--; // if we are not at the top level property then just return if (propertyLevel > 0) { return(fragment); } ColumnFragment column = new ColumnFragment(null, fragment.LastProperty); column.PropertyFragment = fragment; InputFragment input = scope.FindInputFromProperties(fragment); if (input != null) { column.TableName = input.Name; } // now we need to check if our column name was possibly renamed if (input is TableFragment) { if (!string.IsNullOrEmpty(input.Name)) { SelectStatement sf = scope.GetFragment(input.Name) as SelectStatement; if (sf != null) { // Special case: undo alias in case of query fusing for (int i = 0; i < sf.Columns.Count; i++) { ColumnFragment cf = sf.Columns[i]; if (column.ColumnName == cf.ColumnAlias) { column.ColumnName = cf.ColumnName; column.ColumnAlias = cf.ColumnAlias; column.TableName = input.Name; return(column); } } } } return(column); } SelectStatement select = input as SelectStatement; UnionFragment union = input as UnionFragment; if (select != null) { select.HasDifferentNameForColumn(column); } else if (union != null) { union.HasDifferentNameForColumn(column); } // input is a table, selectstatement, or unionstatement return(column); }