Exemple #1
0
        private DbQueryCommandTree Simplify(DbQueryCommandTree view)
        {
            DbExpression query = PatternMatchRuleProcessor.Create(PatternMatchRule.Create(ViewSimplifier._patternCollapseNestedProjection, new Func <DbExpression, DbExpression>(ViewSimplifier.CollapseNestedProjection)), PatternMatchRule.Create(ViewSimplifier._patternCase, new Func <DbExpression, DbExpression>(ViewSimplifier.SimplifyCaseStatement)), PatternMatchRule.Create(ViewSimplifier._patternNestedTphDiscriminator, new Func <DbExpression, DbExpression>(ViewSimplifier.SimplifyNestedTphDiscriminator)), PatternMatchRule.Create(ViewSimplifier._patternEntityConstructor, new Func <DbExpression, DbExpression>(this.AddFkRelatedEntityRefs)))(view.Query);

            view = DbQueryCommandTree.FromValidExpression(view.MetadataWorkspace, view.DataSpace, query, view.UseDatabaseNullSemantics);
            return(view);
        }
Exemple #2
0
        private DbQueryCommandTree Simplify(DbQueryCommandTree view)
        {
            var simplifier = PatternMatchRuleProcessor.Create(
                // determines if an expression is of the form outerProject(outerProjection(innerProject(innerNew)))
                PatternMatchRule.Create(_patternCollapseNestedProjection, CollapseNestedProjection),
                // A case statement can potentially be simplified
                PatternMatchRule.Create(_patternCase, SimplifyCaseStatement),
                // Nested TPH discriminator pattern can be converted to the expected TPH discriminator pattern
                PatternMatchRule.Create(_patternNestedTphDiscriminator, SimplifyNestedTphDiscriminator),
                // Entity constructors may be augmented with FK-based related entity refs
                PatternMatchRule.Create(_patternEntityConstructor, AddFkRelatedEntityRefs)
                );

            var queryExpression = view.Query;

            queryExpression = simplifier(queryExpression);

            view = DbQueryCommandTree.FromValidExpression(view.MetadataWorkspace, view.DataSpace, queryExpression);
            return(view);
        }