GetFragment() public method

public GetFragment ( string name ) : InputFragment
name string
return InputFragment
        public override SqlFragment Visit(DbPropertyExpression expression)
        {
            propertyLevel++;
            PropertyFragment fragment = expression.Instance.Accept(this) as PropertyFragment;

            fragment.Properties.Add(expression.Property.Name);
            propertyLevel--;

            // if we are not at the top level property then just return
            if (propertyLevel > 0)
            {
                return(fragment);
            }

            // we are at the top level property so now we can do our work
            ColumnFragment column = GetColumnFromPropertyTree(fragment);

            for (int i = fragment.Properties.Count - 1; i >= 0; --i)
            {
                InputFragment inputFragment = scope.GetFragment(fragment.Properties[i]);
                if (inputFragment != null)
                {
                    column.TableAlias = inputFragment.Name;
                    break;
                }
            }
            return(column);
        }
Example #2
0
        void AddDefaultColumns(Scope scope)
        {
            if (columnHash == null)
            {
                columnHash = new Dictionary <string, ColumnFragment>();
            }

            List <ColumnFragment> columns = GetDefaultColumnsForFragment(From);
            bool Exists = false;

            if (From is TableFragment && scope.GetFragment((From as TableFragment).Table) == null)
            {
                scope.Add((From as TableFragment).Table, From);
                Exists = true;
            }

            foreach (ColumnFragment column in columns)
            {
                // first we need to set the input for this column
                InputFragment input = scope.FindInputFromProperties(column.PropertyFragment);
                column.TableName = input.Name;

                // then we rename the column if necessary
                if (columnHash.ContainsKey(column.ColumnName.ToUpper()))
                {
                    column.ColumnAlias = MakeColumnNameUnique(column.ColumnName);
                    columnHash.Add(column.ColumnAlias, column);
                }
                else
                {
                    columnHash.Add(column.ColumnName.ToUpper(), column);
                }
                Columns.Add(column);
            }
            if (From is TableFragment && Exists)
            {
                scope.Remove((From as TableFragment).Table, From);
            }
        }
    void AddDefaultColumns(Scope scope)
    {
      if (columnHash == null)
        columnHash = new Dictionary<string, ColumnFragment>();

      List<ColumnFragment> columns = GetDefaultColumnsForFragment(From);
      bool Exists = false;
      if (From is TableFragment && scope.GetFragment((From as TableFragment).Table) == null)
      {
        scope.Add((From as TableFragment).Table, From);
        Exists = true;
      }

      foreach (ColumnFragment column in columns)
      {
        // first we need to set the input for this column
        InputFragment input = scope.FindInputFromProperties(column.PropertyFragment);
        column.TableName = input.Name;

        // then we rename the column if necessary
        if (columnHash.ContainsKey(column.ColumnName.ToUpper()))
        {
          column.ColumnAlias = MakeColumnNameUnique(column.ColumnName);
          columnHash.Add(column.ColumnAlias, column);
        }
        else
          columnHash.Add(column.ColumnName.ToUpper(), column);
        Columns.Add(column);
      }
      if (From is TableFragment && Exists)
      {
        scope.Remove(From);
      }
    }
Example #4
0
        public override SqlFragment Visit(DbPropertyExpression expression)
        {
            propertyLevel++;
            PropertyFragment fragment = expression.Instance.Accept(this) as PropertyFragment;

            fragment.Properties.Add(expression.Property.Name);
            propertyLevel--;

            // if we are not at the top level property then just return
            if (propertyLevel > 0)
            {
                return(fragment);
            }

            ColumnFragment column = new ColumnFragment(null, fragment.LastProperty);

            column.PropertyFragment = fragment;
            InputFragment input = scope.FindInputFromProperties(fragment);

            if (input != null)
            {
                column.TableName = input.Name;
            }

            // now we need to check if our column name was possibly renamed
            if (input is TableFragment)
            {
                if (!string.IsNullOrEmpty(input.Name))
                {
                    SelectStatement sf = scope.GetFragment(input.Name) as SelectStatement;
                    if (sf != null)
                    {
                        // Special case: undo alias in case of query fusing
                        for (int i = 0; i < sf.Columns.Count; i++)
                        {
                            ColumnFragment cf = sf.Columns[i];
                            if (column.ColumnName == cf.ColumnAlias)
                            {
                                column.ColumnName  = cf.ColumnName;
                                column.ColumnAlias = cf.ColumnAlias;
                                column.TableName   = input.Name;
                                return(column);
                            }
                        }
                    }
                }
                return(column);
            }

            SelectStatement select = input as SelectStatement;
            UnionFragment   union  = input as UnionFragment;

            if (select != null)
            {
                select.HasDifferentNameForColumn(column);
            }
            else if (union != null)
            {
                union.HasDifferentNameForColumn(column);
            }

            // input is a table, selectstatement, or unionstatement
            return(column);
        }