private void ParseSelect(string selectClause)
        {
            //Parse fields
            var selectList = selectClause.Substring(7, selectClause.Length - 7).Split(',');

            foreach (string rawField in selectList)
            {
                var s = rawField.Trim();

                //Get Table
                var index = s.IndexOf("]");
                var table = s.Substring(0, index + 1);
                s = s.Substring(table.Length + 1, s.Length - table.Length - 1);

                //Get Name
                index = s.IndexOf("]");
                var field = s.Substring(0, index + 1);

                //Get Alias
                var  alias    = field;
                bool hasAlias = false;
                if (s.Length > field.Length)
                {
                    alias    = s.Substring(field.Length + 4, s.Length - field.Length - 4);
                    hasAlias = true;
                }

                if (!hasAlias)
                {
                    LinqSQLFromClause clause = _fromLinkList.FirstOrDefault(x => x.Alias == table.Replace("[", string.Empty).Replace("]", string.Empty));
                    switch (clause.TableName)
                    {
                    case "CanadaPostalCode": alias = Gravitybox.GeoLocation.EFDAL.Entity.CanadaPostalCode.GetFieldAliasFromFieldNameSqlMapping(field); break;

                    case "City": alias = Gravitybox.GeoLocation.EFDAL.Entity.City.GetFieldAliasFromFieldNameSqlMapping(field); break;

                    case "State": alias = Gravitybox.GeoLocation.EFDAL.Entity.State.GetFieldAliasFromFieldNameSqlMapping(field); break;

                    case "Zip": alias = Gravitybox.GeoLocation.EFDAL.Entity.Zip.GetFieldAliasFromFieldNameSqlMapping(field); break;
                    }
                }

                this.FieldList.Add(new LinqSQLField(field, alias, table));
            }
        }
        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);
                    }
                }
            }
        }