Exemplo n.º 1
0
        protected HqlTreeNode VisitNhAverage(NhAverageExpression expression)
        {
            var hqlExpression = VisitExpression(expression.Expression).AsExpression();

            if (expression.Type != expression.Expression.Type)
            {
                hqlExpression = _hqlTreeBuilder.Cast(hqlExpression, expression.Type);
            }

            return(_hqlTreeBuilder.Cast(_hqlTreeBuilder.Average(hqlExpression), expression.Type));
        }
Exemplo n.º 2
0
        protected HqlTreeNode VisitNhAverage(NhAverageExpression expression)
        {
            // We need to cast the argument when its type is different from Average method return type,
            // otherwise the result may be incorrect. In SQL Server avg always returns int
            // when the argument is int.
            var hqlExpression = VisitExpression(expression.Expression).AsExpression();

            hqlExpression = IsCastRequired(expression.Expression, expression.Type, out _)
                                ? (HqlExpression)_hqlTreeBuilder.Cast(hqlExpression, expression.Type)
                                : _hqlTreeBuilder.TransparentCast(hqlExpression, expression.Type);

            // In Oracle the avg function can return a number with up to 40 digits which cannot be retrieved from the data reader due to the lack of such
            // numeric type in .NET. In order to avoid that we have to add a cast to trim the number so that it can be converted into a .NET numeric type.
            return(_hqlTreeBuilder.Cast(_hqlTreeBuilder.Average(hqlExpression), expression.Type));
        }
Exemplo n.º 3
0
 protected HqlTreeNode VisitNhAverage(NhAverageExpression expression)
 {
     return(_hqlTreeBuilder.Cast(_hqlTreeBuilder.Average(VisitExpression(expression.Expression).AsExpression()), expression.Type));
 }