public SqlField RegisterFieldMapping(ISqlExpression baseExpression, ISqlExpression expression, int index, Func <SqlField> fieldFactory) { var baseField = baseExpression as SqlField; if (baseField != null && FieldIndexesByName.TryGetValue(baseField.Name, out var value)) { return(value.Item1); } if (baseField == null && expression != null && FieldIndexes.TryGetValue(expression, out value)) { return(value.Item1); } var newField = fieldFactory(); Utils.MakeUniqueNames(new[] { newField }, FieldIndexes.Values.Select(t => t.Item1.Name), f => f.Name, (f, n) => { f.Name = n; f.PhysicalName = n; }, f => "cte_field"); Fields.Insert(index, newField); if (expression != null && !FieldIndexes.ContainsKey(expression)) { FieldIndexes.Add(expression, Tuple.Create(newField, index)); } if (baseField != null) { FieldIndexesByName.Add(baseField.Name, Tuple.Create(newField, index)); } return(newField); }
public int GetSubtypeFieldIndex(ITable table) { FieldIndexes fieldIndexes; if (!_fieldIndexesByTable.TryGetValue(table, out fieldIndexes)) { fieldIndexes = new FieldIndexes(table); _fieldIndexesByTable.Add(table, fieldIndexes); } return(fieldIndexes.GetSubtypeFieldIndex()); }
public int GetFieldIndex(ITable table, string fieldName, AttributeRole role) { FieldIndexes fieldIndexes; if (!_fieldIndexesByTable.TryGetValue(table, out fieldIndexes)) { fieldIndexes = new FieldIndexes(table); _fieldIndexesByTable.Add(table, fieldIndexes); } return(fieldIndexes.GetFieldIndex(fieldName, role)); }