public static string GetRemappedLinqSql(LinqSQLFromClause tableInfo, string whereClause, LinqSQLFromClauseCollection fromLinkList, ObjectTypeConstants type) { if (type == ObjectTypeConstants.Table) { switch (tableInfo.TableName) { case "CanadaPostalCode": return(Gravitybox.GeoLocation.EFDAL.Entity.CanadaPostalCode.GetRemappedLinqSql(whereClause, tableInfo.Alias, fromLinkList)); case "City": return(Gravitybox.GeoLocation.EFDAL.Entity.City.GetRemappedLinqSql(whereClause, tableInfo.Alias, fromLinkList)); case "State": return(Gravitybox.GeoLocation.EFDAL.Entity.State.GetRemappedLinqSql(whereClause, tableInfo.Alias, fromLinkList)); case "Zip": return(Gravitybox.GeoLocation.EFDAL.Entity.Zip.GetRemappedLinqSql(whereClause, tableInfo.Alias, fromLinkList)); } } if (type == ObjectTypeConstants.View) { } if (type == ObjectTypeConstants.StoredProcedure) { } throw new Exception("Table not found '" + tableInfo.TableName + "'."); }
private void RemapParentChild() { //Include all base tables LinqSQLFromClauseCollection childTables = new LinqSQLFromClauseCollection(); foreach (var fromClause in _fromLinkList) { //Do all field replacements if (_type == ObjectTypeConstants.Table) { if (fromClause.TableName == "CanadaPostalCode") { childTables.Add(fromClause); } if (fromClause.TableName == "City") { childTables.Add(fromClause); } if (fromClause.TableName == "State") { childTables.Add(fromClause); } if (fromClause.TableName == "Zip") { childTables.Add(fromClause); } } if (_type == ObjectTypeConstants.View) { } } _fromLinkList.Clear(); _fromLinkList.AddRange(childTables); //Process the FROM clause _fromLinkList.RemapFromClause(); //Now map the columns to the proper tables foreach (var field in this.FieldList) { LinqSQLFromClause clause = _fromLinkList.FirstOrDefault(x => x.Alias == field.Table); string realTable = string.Empty; if (_type == ObjectTypeConstants.Table) { if (clause.TableName == "CanadaPostalCode") { realTable = Gravitybox.GeoLocation.EFDAL.Entity.CanadaPostalCode.GetTableFromFieldAliasSqlMapping(field.Alias); } else if (clause.TableName == "City") { realTable = Gravitybox.GeoLocation.EFDAL.Entity.City.GetTableFromFieldAliasSqlMapping(field.Alias); } else if (clause.TableName == "State") { realTable = Gravitybox.GeoLocation.EFDAL.Entity.State.GetTableFromFieldAliasSqlMapping(field.Alias); } else if (clause.TableName == "Zip") { realTable = Gravitybox.GeoLocation.EFDAL.Entity.Zip.GetTableFromFieldAliasSqlMapping(field.Alias); } } var sqlFromClause = _fromLinkList.GetByTable(realTable); field.Table = sqlFromClause.Alias; } //Calculate the WHERE clause if (!string.IsNullOrEmpty(_whereClause)) { foreach (var fromClause in _fromLinkList) { //Only process table that were original and not inserted above if (fromClause.AnchorAlias == string.Empty) { _whereClause = GetRemappedLinqSql(fromClause, _whereClause, _fromLinkList, _type); } } } }