Ejemplo n.º 1
0
        protected HqlTreeNode VisitConstantExpression(ConstantExpression expression)
        {
            if (expression.Value != null)
            {
                IEntityNameProvider entityName = expression.Value as IEntityNameProvider;
                if (entityName != null)
                {
                    return(_hqlTreeBuilder.Ident(entityName.EntityName));
                }
            }

            NamedParameter namedParameter;

            if (_parameters.ConstantToParameterMap.TryGetValue(expression, out namedParameter))
            {
                _parameters.RequiredHqlParameters.Add(new NamedParameterDescriptor(namedParameter.Name, null, false));
                var parameter = _hqlTreeBuilder.Parameter(namedParameter.Name).AsExpression();

                // SQLite driver binds decimal parameters to text, which can cause unexpected results in arithmetic operations.
                return(_parameters.SessionFactory.Dialect.IsDecimalStoredAsFloatingPointNumber && expression.Type.UnwrapIfNullable() == typeof(decimal)
                                        ? _hqlTreeBuilder.TransparentCast(parameter, expression.Type)
                                        : parameter);
            }

            return(_hqlTreeBuilder.Constant(expression.Value));
        }
        protected HqlTreeNode VisitConstantExpression(ConstantExpression expression)
        {
            if (expression.Value != null)
            {
                IEntityNameProvider entityName = expression.Value as IEntityNameProvider;
                if (entityName != null)
                {
                    return(_hqlTreeBuilder.Ident(entityName.EntityName));
                }
            }

            NamedParameter namedParameter;

            if (_parameters.ConstantToParameterMap.TryGetValue(expression, out namedParameter))
            {
                _parameters.RequiredHqlParameters.Add(new NamedParameterDescriptor(namedParameter.Name, null, false));

                if (namedParameter.Value is bool)
                {
                    return(_hqlTreeBuilder.Equality(_hqlTreeBuilder.Parameter(namedParameter.Name).AsExpression(), _hqlTreeBuilder.Constant(true)));
                }

                return(_hqlTreeBuilder.Parameter(namedParameter.Name).AsExpression());
            }

            return(_hqlTreeBuilder.Constant(expression.Value));
        }