/// <summary> /// Constructor. /// </summary> private GXSelectArgs() { Parent = new GXSettingsArgs(); Joins = new GXJoinCollection(Parent); Columns = new GXColumnCollection(Parent); Columns.Joins = Joins; Where = new GXWhereCollection(Parent); OrderBy = new GXOrderByCollection(this); }
public override string ToString() { if (Parent.Updated || Updated) { ColumnList.Clear(); List <GXJoin> joinList = new List <GXJoin>(); GXOrderByCollection.UpdateJoins(Parent.Settings, Joins, joinList); string[] list; StringBuilder sb = new StringBuilder(); //Get columns. Dictionary <string, GXSerializedItem> properties; Dictionary <Type, GXSerializedItem> neededTables = new Dictionary <Type, GXSerializedItem>(); foreach (var it in List) { //No relations. if (!neededTables.ContainsKey(it.Parameters[0].Type)) { neededTables.Add(it.Parameters[0].Type, null); } list = GXDbHelpers.GetMembers(Parent.Settings, it, '\0', false); foreach (var it2 in list) { properties = GXSqlBuilder.GetProperties(it.Parameters[0].Type); if (it2 != "*" && ColumnList.ContainsKey(it.Parameters[0].Type)) { GXSerializedItem si = properties[it2]; if (si.Relation != null) { //Get properties. GetColumns(si.Relation.ForeignTable, ColumnList, neededTables); } if (si.Relation == null || si.Relation.RelationType != RelationType.ManyToMany) { ColumnList[it.Parameters[0].Type].Add(it2); } } else { if (it2 == "*") { GetColumns(it.Parameters[0].Type, ColumnList, neededTables); } else { if (neededTables.ContainsKey(it.Parameters[0].Type)) { neededTables.Remove(it.Parameters[0].Type); } List <string> columns2 = new List <string>(); columns2.Add(it2); ColumnList.Add(it.Parameters[0].Type, columns2); if (properties.ContainsKey(it2)) { GXSerializedItem si = properties[it2]; if (si.Relation != null) { //Get properties. GetColumns(si.Relation.ForeignTable, ColumnList, neededTables); } } } } } } foreach (var it in ColumnList) { foreach (KeyValuePair <Type, LambdaExpression> x in Excluded) { if (x.Key == it.Key) { string[] removed = GXDbHelpers.GetMembers(null, x.Value, '\0', false); foreach (string col in removed) { it.Value.Remove(col); } } } } SelectToString(Parent.Settings, sb, Parent.Distinct, ColumnList, joinList, Parent.Index, Parent.Count); sql = sb.ToString(); Updated = false; } return(sql); }
internal string ToString(ref string post) { if (Parent.Updated || Updated) { ColumnList.Clear(); List <GXJoin> joinList = new List <GXJoin>(); GXOrderByCollection.UpdateJoins(Parent.Settings, Joins, joinList); string[] list; StringBuilder sb = new StringBuilder(); //Get columns. Dictionary <string, GXSerializedItem> properties; Dictionary <Type, GXSerializedItem> neededTables = new Dictionary <Type, GXSerializedItem>(); foreach (var it in List) { //No relations. if (!neededTables.ContainsKey(it.Key.Parameters[0].Type)) { neededTables.Add(it.Key.Parameters[0].Type, null); } list = GXDbHelpers.GetMembers(Parent.Settings, it.Key, '\0', false, ref post); foreach (var it2 in list) { properties = GXSqlBuilder.GetProperties(it.Key.Parameters[0].Type); if (it2 != "*" && ColumnList.ContainsKey(it.Key.Parameters[0].Type)) { if (properties.ContainsKey(it2)) { GXSerializedItem si = properties[it2]; if (si.Relation != null) { //Get properties. GetColumns(si.Relation.ForeignTable, ColumnList, neededTables); } if (si.Relation == null || si.Relation.RelationType != RelationType.ManyToMany) { ColumnList[it.Key.Parameters[0].Type].Add(it2); } } else { string str = it2; if (it.Value != null) { string[] tmp = GXDbHelpers.GetMembers(Parent.Settings, it.Value, '\0', false, ref post); str += " AS " + tmp[0]; } ColumnList[it.Key.Parameters[0].Type].Add(str); } } else { if (it2 == "*") { GetColumns(it.Key.Parameters[0].Type, ColumnList, neededTables); } else { if (neededTables.ContainsKey(it.Key.Parameters[0].Type)) { neededTables.Remove(it.Key.Parameters[0].Type); } List <string> columns2 = new List <string>(); columns2.Add(it2); ColumnList.Add(it.Key.Parameters[0].Type, columns2); if (properties.ContainsKey(it2)) { GXSerializedItem si = properties[it2]; if (si.Relation != null) { //Get properties. GetColumns(si.Relation.ForeignTable, ColumnList, neededTables); } } } } } } foreach (var it in ColumnList) { foreach (KeyValuePair <Type, LambdaExpression> x in Excluded) { if (x.Key == it.Key) { string[] removed = GXDbHelpers.GetMembers(null, x.Value, '\0', false, ref post); foreach (string col in removed) { bool includeQuery = false; string col2 = GXDbHelpers.AddQuotes(col, Parent.Settings.ColumnQuotation); //Joins are not removed from the qyery or 1:1 doesn't work. foreach (var j in joinList) { if ((it.Key == j.Table1Type && j.Column1 == col2) || (it.Key == j.Table2Type && j.Column2 == col2)) { includeQuery = true; break; } } if (!includeQuery) { it.Value.Remove(col); } } } } } SelectToString(Parent.Settings, sb, Parent.Distinct, ColumnList, joinList, Parent.Index, Parent.Count, post); sql = sb.ToString(); Updated = false; } return(sql); }