internal static string Where(GXDBSettings Settings, LambdaExpression value, bool removebrackets) { if (value != null) { string str; string post = null; if (Settings.UseQuotationWhereColumns) { str = GXDbHelpers.GetMembers(Settings, value.Body, Settings.ColumnQuotation, true, ref post)[0]; } else { str = GXDbHelpers.GetMembers(Settings, value.Body, '\'', true, ref post)[0]; } //Remove brackets. if (removebrackets && str.Length > 2) { return(str.Substring(1, str.Length - 2)); } else { return(str); } } return(null); }
/// <summary> /// Order values by. /// </summary> /// <param name="sourceColumn">Columns order by.</param> internal static void OrderBy(GXDBSettings settings, LambdaExpression sourceColumn, List <GXOrder> OrderList) { string[] list = GXDbHelpers.GetMembers(settings, sourceColumn.Body, '\0', false); foreach (string it in list) { GXOrder o = new GXOrder(); o.Table = sourceColumn.Parameters[0].Type; o.Column = it; OrderList.Add(o); } }
private void UpdateMaps(GXDBSettings settings, GXMapCollection list, List <GXJoin> joins) { Select.Columns.Maps.Clear(); foreach (BinaryExpression it in list.List) { var e = (MemberExpression)it.Right; string[] target = GXDbHelpers.GetMembers(settings, it.Left, settings.TableQuotation, false, false); string[] source = GXDbHelpers.GetMembers(settings, it.Right, settings.TableQuotation, false, false); Select.Columns.Maps.Add(source[0], target[0]); } }
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); }