private void AddSelectField(StringBuilder fieldList, StringBuilder fromList, Hashtable lookupTables, FieldMap field) { if (!field.IsLookup) { fieldList.Append(this.GetDelimited(this.entity.Table, field.Field) + ", "); } else { LookupMap lookup = field as LookupMap; string lookupKey = string.Format("{0};{1};{2}", lookup.Table.ToUpper(), string.Join(",", lookup.Source).ToUpper(), string.Join(",", lookup.Dest).ToUpper()); if (!lookupTables.ContainsKey(lookupKey)) { string lookupTable = lookup.Table.Substring(lookup.Table.LastIndexOf('.') + 1); lookup.tableAlias = lookupTable + "_" + (lookupTables.Count + 1).ToString(); lookupTables.Add(lookupKey, lookup.tableAlias); StringBuilder join = new StringBuilder(); join.AppendFormat(" LEFT JOIN {0} {1} {2} ON", this.GetDelimited(lookup.Table), this.provider.ColumnAliasKeyword, this.GetDelimited(lookup.TableAlias, true) + this.GetPostHint()); for (int fkey = 0; fkey < lookup.Source.Length; fkey++) { join.AppendFormat(" {0} = {1} AND", this.GetDelimited(this.entity.Table, lookup.Source[fkey]), this.GetDelimited(lookup.TableAlias, lookup.Dest[fkey])); } fromList.Append(join.Remove(join.Length - 4, 4).ToString() + ")"); } else { lookup.tableAlias = (string)lookupTables[lookupKey]; } fieldList.AppendFormat("{0} {1} {2}, ", this.GetDelimited(lookup.TableAlias, lookup.Field), this.provider.ColumnAliasKeyword, this.GetDelimited(lookup.FieldAlias)); } }
private bool CanLookupMapsUseSameJoin(LookupMap a, LookupMap b) { if( string.Compare(a.Table, b.Table, true) != 0 ) { return false; } if( a.Source.Length != b.Source.Length ) { return false; } if( a.Dest.Length != b.Dest.Length ) { return false; } for( int i = 0; i < a.Source.Length; i++) { if( string.Compare(a.Source[i], b.Source[i], true) != 0 ) { return false; } } for( int i = 0; i < a.Dest.Length; i++) { if( string.Compare(a.Dest[i], b.Dest[i], true) != 0 ) { return false; } } return true; }