Exemplo n.º 1
0
        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 "ConfigSetting": alias = Gravitybox.gFileSystem.EFDAL.Entity.ConfigSetting.GetFieldAliasFromFieldNameSqlMapping(field); break;

                    case "Container": alias = Gravitybox.gFileSystem.EFDAL.Entity.Container.GetFieldAliasFromFieldNameSqlMapping(field); break;

                    case "FileStash": alias = Gravitybox.gFileSystem.EFDAL.Entity.FileStash.GetFieldAliasFromFieldNameSqlMapping(field); break;

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

                this.FieldList.Add(new LinqSQLField(field, alias, table));
            }
        }
Exemplo n.º 2
0
        public static string GetRemappedLinqSql(LinqSQLFromClause tableInfo, string whereClause, LinqSQLFromClauseCollection fromLinkList, ObjectTypeConstants type)
        {
            if (type == ObjectTypeConstants.Table)
            {
                switch (tableInfo.TableName)
                {
                case "ConfigSetting": return(Gravitybox.gFileSystem.EFDAL.Entity.ConfigSetting.GetRemappedLinqSql(whereClause, tableInfo.Alias, fromLinkList));

                case "Container": return(Gravitybox.gFileSystem.EFDAL.Entity.Container.GetRemappedLinqSql(whereClause, tableInfo.Alias, fromLinkList));

                case "FileStash": return(Gravitybox.gFileSystem.EFDAL.Entity.FileStash.GetRemappedLinqSql(whereClause, tableInfo.Alias, fromLinkList));

                case "Tenant": return(Gravitybox.gFileSystem.EFDAL.Entity.Tenant.GetRemappedLinqSql(whereClause, tableInfo.Alias, fromLinkList));
                }
            }
            if (type == ObjectTypeConstants.View)
            {
            }
            if (type == ObjectTypeConstants.StoredProcedure)
            {
            }
            throw new Exception("Table not found '" + tableInfo.TableName + "'.");
        }
Exemplo n.º 3
0
        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 == "ConfigSetting")
                    {
                        childTables.Add(fromClause);
                    }
                    if (fromClause.TableName == "Container")
                    {
                        childTables.Add(fromClause);
                    }
                    if (fromClause.TableName == "FileStash")
                    {
                        childTables.Add(fromClause);
                    }
                    if (fromClause.TableName == "Tenant")
                    {
                        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 == "ConfigSetting")
                    {
                        realTable = Gravitybox.gFileSystem.EFDAL.Entity.ConfigSetting.GetTableFromFieldAliasSqlMapping(field.Alias);
                    }
                    else if (clause.TableName == "Container")
                    {
                        realTable = Gravitybox.gFileSystem.EFDAL.Entity.Container.GetTableFromFieldAliasSqlMapping(field.Alias);
                    }
                    else if (clause.TableName == "FileStash")
                    {
                        realTable = Gravitybox.gFileSystem.EFDAL.Entity.FileStash.GetTableFromFieldAliasSqlMapping(field.Alias);
                    }
                    else if (clause.TableName == "Tenant")
                    {
                        realTable = Gravitybox.gFileSystem.EFDAL.Entity.Tenant.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);
                    }
                }
            }
        }