private DbQueryCommandTree Simplify(DbQueryCommandTree view)
        {
            var simplifier = PatternMatchRuleProcessor.Create(
                // determines if an expression is of the form outerProject(outerProjection(innerProject(innerNew)))
                PatternMatchRule.Create(Pattern_CollapseNestedProjection, ViewSimplifier.CollapseNestedProjection),

                // A case statement can potentially be simplified
                PatternMatchRule.Create(Pattern_Case, ViewSimplifier.SimplifyCaseStatement),

                // Nested TPH discriminator pattern can be converted to the expected TPH discriminator pattern
                PatternMatchRule.Create(Pattern_NestedTphDiscriminator, ViewSimplifier.SimplifyNestedTphDiscriminator),

                // Entity constructors may be augmented with FK-based related entity refs
                PatternMatchRule.Create(Pattern_EntityConstructor, this.AddFkRelatedEntityRefs)
                );

            DbExpression queryExpression = view.Query;

            queryExpression = simplifier(queryExpression);

            view = DbQueryCommandTree.FromValidExpression(view.MetadataWorkspace, view.DataSpace, queryExpression);
            return(view);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Constructs a new PatternMatch rule with the specified pattern, processor and default <see cref="DbExpressionRule.ProcessedAction"/> of <see cref="DbExpressionRule.ProcessedAction.Reset"/>
 /// </summary>
 internal static PatternMatchRule Create(Func <DbExpression, bool> matchFunc, Func <DbExpression, DbExpression> processor)
 {
     return(PatternMatchRule.Create(matchFunc, processor, ProcessedAction.Reset));
 }