public Expression VisitSqlGroupingSelectExpression(SqlGroupingSelectExpression expression)
        {
            ArgumentUtility.CheckNotNull("expression", expression);

            var referenceToKeyExpression          = ResolveChildExpression(expression.KeyExpression);
            var referenceToElementExpression      = ResolveChildExpression(expression.ElementExpression);
            var referenceToAggregationExpressions = expression.AggregationExpressions.Select(expr => ResolveChildExpression(expr));

            var newGroupingExpression = SqlGroupingSelectExpression.CreateWithNames(referenceToKeyExpression, referenceToElementExpression);

            foreach (var aggregationExpression in referenceToAggregationExpressions)
            {
                newGroupingExpression.AddAggregationExpressionWithName(aggregationExpression);
            }

            _context.AddGroupReferenceMapping(newGroupingExpression, _sqlTable);

            return(newGroupingExpression);
        }
Example #2
0
        public void ProcessNames_SqlGroupingSelectExpression()
        {
            var keyExpression            = new NamedExpression("key", Expression.Constant("key"));
            var elementExpression        = new NamedExpression("element", Expression.Constant("element"));
            var aggregationExpression    = new NamedExpression("a0", Expression.Constant("aggregation"));
            var groupingSelectExpression = new SqlGroupingSelectExpression(keyExpression, elementExpression, new[] { aggregationExpression });
            var expression = new NamedExpression("outer", groupingSelectExpression);
            var sqlTable   = SqlStatementModelObjectMother.CreateSqlTable(typeof(Cook));

            _context.AddGroupReferenceMapping(groupingSelectExpression, sqlTable);

            var expectedResult = new SqlGroupingSelectExpression(
                new NamedExpression("outer_key", Expression.Constant("key")),
                new NamedExpression("outer_element", Expression.Constant("element")),
                new[] { new NamedExpression("outer_a0", Expression.Constant("aggregation")) });

            var result = _namedExpressionCombiner.ProcessNames(expression);

            SqlExpressionTreeComparer.CheckAreEqualTrees(result, expectedResult);
            Assert.That(_context.GetReferencedGroupSource(((SqlGroupingSelectExpression)result)), Is.SameAs(sqlTable));
        }