Inheritance: InputFragment
Exemplo n.º 1
0
        public override SqlFragment Visit(DbScanExpression expression)
        {
            EntitySetBase target   = expression.Target;
            TableFragment fragment = new TableFragment();

            MetadataProperty property;
            bool             propExists = target.MetadataProperties.TryGetValue("DefiningQuery", true, out property);

            if (propExists && property.Value != null)
            {
                fragment.DefiningQuery = new LiteralFragment(property.Value as string);
            }
            else
            {
                fragment.Schema = target.EntityContainer.Name;
                fragment.Table  = target.Name;

                propExists = target.MetadataProperties.TryGetValue("Schema", true, out property);
                if (propExists && property.Value != null)
                {
                    fragment.Schema = property.Value as string;
                }
                propExists = target.MetadataProperties.TryGetValue("Table", true, out property);
                if (propExists && property.Value != null)
                {
                    fragment.Table = property.Value as string;
                }
            }
            return(fragment);
        }
Exemplo n.º 2
0
        void AddDefaultColumnsForTable(TableFragment table)
        {
            if (columnHash == null)
            {
                columnHash = new Dictionary <string, ColumnFragment>();
            }

            foreach (EdmProperty property in Metadata.GetProperties(table.Type.EdmType))
            {
                ColumnFragment col = new ColumnFragment(table.Name, property.Name);
                if (table.Columns == null)
                {
                    table.Columns = new List <ColumnFragment>();
                }
                table.Columns.Add(col);
                if (columnHash.ContainsKey(col.ColumnName))
                {
                    col.ColumnAlias = MakeColumnNameUnique(col.ColumnName);
                    columnHash.Add(col.ColumnAlias, col);
                }
                else
                {
                    columnHash.Add(col.ColumnName, col);
                }
                Columns.Add(col);
            }
        }
Exemplo n.º 3
0
        List <ColumnFragment> GetDefaultColumnsForTable(TableFragment table)
        {
            List <ColumnFragment> columns = new List <ColumnFragment>();

            foreach (EdmProperty property in Metadata.GetProperties(table.Type.EdmType))
            {
                ColumnFragment col = new ColumnFragment(table.Name, property.Name);
                col.PushInput(property.Name);
                col.PushInput((table.Name != null) ? table.Name : table.Table);
                columns.Add(col);
            }
            return(columns);
        }
Exemplo n.º 4
0
        public override SqlFragment Visit(DbScanExpression expression)
        {
            EntitySetBase target   = expression.Target;
            TableFragment fragment = new TableFragment();

            MetadataProperty property;
            bool             propExists = target.MetadataProperties.TryGetValue("DefiningQuery", true, out property);

            if (propExists && property.Value != null)
            {
                MetadataProperty prop2;

                if (target.MetadataProperties.TryGetValue("http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator:Type", true, out prop2) && (prop2.Value as string == "Views"))

                {
                    // avoid storing view query as DefiningQuery because that hurts query fusing.
                    fragment.Schema = target.MetadataProperties.GetValue("http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator:Schema", true).Value as string;
                    fragment.Table  = target.Name;
                }
                else
                {
                    fragment.DefiningQuery = new LiteralFragment(property.Value as string);
                }
            }

            else
            {
                fragment.Schema = target.EntityContainer.Name;
                fragment.Table  = target.Name;

                propExists = target.MetadataProperties.TryGetValue("Schema", true, out property);
                if (propExists && property.Value != null)
                {
                    fragment.Schema = property.Value as string;
                }
                propExists = target.MetadataProperties.TryGetValue("Table", true, out property);
                if (propExists && property.Value != null)
                {
                    fragment.Table = property.Value as string;
                }
            }
            return(fragment);
        }
Exemplo n.º 5
0
    List<ColumnFragment> GetDefaultColumnsForTable(TableFragment table)
    {
      List<ColumnFragment> columns = new List<ColumnFragment>();

      foreach (EdmProperty property in Metadata.GetProperties(table.Type.EdmType))
      {
        ColumnFragment col = new ColumnFragment(table.Name, property.Name);
        col.PushInput(property.Name);
        col.PushInput((table.Name != null) ? table.Name : table.Table);
        columns.Add(col);
      }
      return columns;
    }
 public void Visit(TableFragment f)
 {
 }
Exemplo n.º 7
0
 public void Visit(TableFragment f)
 {
 }
Exemplo n.º 8
0
        /// <summary>
        /// If input sqlFragment is a group by structure, is flattened to remove some nested correlation queries.
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        private SqlFragment TryFlatteningGroupBy(SqlFragment input)
        {
            SelectStatement select = null;
            SelectStatement tmpFrag = null, tmpFrag2 = null, tmpFrag3 = null;
            InputFragment   table = null;
            string          objName = null, colName = null, queryName = null;

            // First part assert is a kind-of structure we are looking for
            tmpFrag = input as SelectStatement;
            if (tmpFrag == null)
            {
                goto NoChanges;
            }
            tmpFrag = (tmpFrag).From as SelectStatement;
            if (tmpFrag == null)
            {
                goto NoChanges;
            }
            queryName = tmpFrag.Name;
            if (tmpFrag.Columns.Count < 2)
            {
                goto NoChanges;
            }
            if (!(tmpFrag.Columns[0] is ColumnFragment))
            {
                goto NoChanges;
            }
            colName  = objName = (tmpFrag.Columns[0] as ColumnFragment).ActualColumnName;
            tmpFrag2 = tmpFrag.From as SelectStatement;
            if (tmpFrag2 == null)
            {
                goto NoChanges;
            }
            if (tmpFrag2.Columns.Count < 1 || !(tmpFrag2.Columns[0] is ColumnFragment))
            {
                goto NoChanges;
            }
            if (string.CompareOrdinal(objName, tmpFrag2.Columns[0].ActualColumnName) != 0)
            {
                goto NoChanges;
            }
            if (tmpFrag.Columns[1].Literal == null)
            {
                goto NoChanges;
            }
            tmpFrag2 = tmpFrag.Columns[1].Literal as SelectStatement;
            if (tmpFrag2 == null)
            {
                goto NoChanges;
            }
            if ((tmpFrag2.Columns.Count != 1) || !(tmpFrag2.Columns[0].Literal != null))
            {
                goto NoChanges;
            }
            tmpFrag3 = tmpFrag2.From as SelectStatement;
            if (tmpFrag3 == null)
            {
                goto NoChanges;
            }
            table = tmpFrag3.From as InputFragment;
            if (table == null)
            {
                goto NoChanges;
            }
            FunctionFragment func = tmpFrag2.Columns[0].Literal as FunctionFragment;

            if (tmpFrag3.Columns.Count != 1 || !(tmpFrag3.Columns[0] is ColumnFragment))
            {
                goto NoChanges;
            }
            if (func == null)
            {
                goto NoChanges;
            }
            // Yes it is the kind-of type we like, then optimize it
            select     = new SelectStatement(this);
            table.Name = null;
            string        tableName = null;
            TableFragment t         = tmpFrag3.From as TableFragment;

            if (t == null)
            {
                tableName = tmpFrag3.Columns[0].TableName;
            }
            else
            {
                tableName = t.Table;
            }
            select.From = table;
            select.Columns.Add(new ColumnFragment(tableName, colName));
            select.Columns.Add(new ColumnFragment(tableName, "C0")
            {
                ColumnAlias = "C1",
                Literal     = new FunctionFragment()
                {
                    Argument = new ColumnFragment(tableName, tmpFrag3.Columns[0].ActualColumnName),
                    Distinct = tmpFrag3.IsDistinct,
                    Name     = func.Name
                }
            });
            select.Wrap(null);
            select.Name = queryName;
            select.AddGroupBy(select.Columns[0]);
            (input as SelectStatement).From = select;
NoChanges:
            return(input);
        }
        void AddDefaultColumnsForTable(TableFragment table)
        {
            if (columnHash == null)
                columnHash = new Dictionary<string, ColumnFragment>();

            foreach (EdmProperty property in Metadata.GetProperties(table.Type.EdmType))
            {
                ColumnFragment col = new ColumnFragment(table.Name, property.Name);
                if (table.Columns == null)
                    table.Columns = new List<ColumnFragment>();
                table.Columns.Add(col);
                if (columnHash.ContainsKey(col.ColumnName))
                {
                    col.ColumnAlias = MakeColumnNameUnique(col.ColumnName);
                    columnHash.Add(col.ColumnAlias, col);
                }
                else
                    columnHash.Add(col.ColumnName, col);
                Columns.Add(col);
            }
        }