private ICriterion CreateLikeCriterion(Expression projectionExpression, Expression literalExpression, MatchMode matchMode)
        {
            var projection = ProjectionVisitor.CreateProjection(projectionExpression);
            var value      = LiteralUtil.CoerceString((LiteralExpression)literalExpression);

            return(_context.CaseSensitiveLike ? Restrictions.Like(projection, value, matchMode) : Restrictions.InsensitiveLike(projection, value, matchMode));
        }
Ejemplo n.º 2
0
 public override IProjection ToLowerMethod(ToLowerMethod method, Expression[] arguments)
 {
     return(new SqlFunctionProjection(
                "lower",
                NHibernateUtil.String,
                ProjectionVisitor.CreateProjection(arguments[0])
                ));
 }
Ejemplo n.º 3
0
 public override IProjection LengthMethod(LengthMethod method, Expression[] arguments)
 {
     return(new SqlFunctionProjection(
                "length",
                NHibernateUtil.Int32,
                ProjectionVisitor.CreateProjection(arguments[0])
                ));
 }
Ejemplo n.º 4
0
 private IProjection DatePartMethod(DatePartMethod method, Expression[] arguments, string function)
 {
     return(new SqlFunctionProjection(
                function,
                NHibernateUtil.Int32,
                ProjectionVisitor.CreateProjection(arguments[0])
                ));
 }
Ejemplo n.º 5
0
 public override IProjection ReplaceMethod(ReplaceMethod method, Expression[] arguments)
 {
     return(new SqlFunctionProjection(
                "replace",
                NHibernateUtil.String,
                ProjectionVisitor.CreateProjection(arguments[0]),
                ProjectionVisitor.CreateProjection(arguments[1]),
                ProjectionVisitor.CreateProjection(arguments[2])
                ));
 }
Ejemplo n.º 6
0
        public override IProjection IndexOfMethod(IndexOfMethod method, Expression[] arguments)
        {
            // The standard registered locate function expects three parameters,
            // and the rest seems tot support it.

            return(new SqlFunctionProjection(
                       "locate",
                       NHibernateUtil.Int32,
                       ProjectionVisitor.CreateProjection(arguments[1]),
                       ProjectionVisitor.CreateProjection(arguments[0]),
                       Projections.Constant(1)
                       ));
        }
Ejemplo n.º 7
0
        public OrderBy[] Parse()
        {
            var orderBys = new List <OrderBy>();

            while (true)
            {
                var result = ParseCommon();

                var projection = ProjectionVisitor.CreateProjection(
                    result.Visit(_normalizeVisitor)
                    );

                if (AtEnd)
                {
                    orderBys.Add(new OrderBy(projection, OrderByDirection.Ascending));

                    break;
                }
                else
                {
                    var direction = GetOrderByDirection(Current);

                    if (!direction.HasValue)
                    {
                        direction = OrderByDirection.Ascending;
                    }
                    else
                    {
                        MoveNext();
                    }

                    orderBys.Add(new OrderBy(projection, direction.Value));

                    if (AtEnd)
                    {
                        break;
                    }

                    if (Current != SyntaxToken.Comma)
                    {
                        throw new ODataException(ErrorMessages.OrderByParser_ExpectedNextOrEnd);
                    }

                    MoveNext();
                }
            }

            return(orderBys.ToArray());
        }
Ejemplo n.º 8
0
 public override IProjection ConcatMethod(ConcatMethod method, Expression[] arguments)
 {
     if (arguments.Length == 1)
     {
         return(ProjectionVisitor.CreateProjection(arguments[0]));
     }
     else
     {
         return(new SqlFunctionProjection(
                    "concat",
                    NHibernateUtil.String,
                    ProjectionVisitor.CreateProjection(arguments[0]),
                    ProjectionVisitor.CreateProjection(arguments[1])
                    ));
     }
 }
Ejemplo n.º 9
0
        public override IProjection CastMethod(CastMethod method, Expression[] arguments)
        {
            var projection = ProjectionVisitor.CreateProjection(arguments[0]);

            switch (LiteralUtil.CoerceString((LiteralExpression)arguments[1]))
            {
            case "Edm.Byte":
            case "Edm.SByte":
            case "Edm.Int16":
            case "Edm.Int32":
                return(new SqlFunctionProjection("round", NHibernateUtil.Int32, projection));

            case "Edm.Int64":
                return(new SqlFunctionProjection("round", NHibernateUtil.Int64, projection));

            default:
                return(projection);
            }
        }
Ejemplo n.º 10
0
 public override IProjection SubStringMethod(SubStringMethod method, Expression[] arguments)
 {
     if (arguments.Length == 2)
     {
         return(new SqlFunctionProjection(
                    "substring",
                    NHibernateUtil.String,
                    ProjectionVisitor.CreateProjection(arguments[0]),
                    ProjectionVisitor.CreateProjection(arguments[1])
                    ));
     }
     else
     {
         return(new SqlFunctionProjection(
                    "substring",
                    NHibernateUtil.String,
                    ProjectionVisitor.CreateProjection(arguments[0]),
                    ProjectionVisitor.CreateProjection(arguments[1]),
                    ProjectionVisitor.CreateProjection(arguments[2])
                    ));
     }
 }
Ejemplo n.º 11
0
        public override ICriterion ComparisonExpression(ComparisonExpression expression)
        {
            IProjection left;
            IProjection right;
            var         leftExpression  = expression.Left;
            var         rightExpression = expression.Right;

            // Swap the expressions if the left operand is null.

            if (IsNull(leftExpression))
            {
                var tmp = leftExpression;
                leftExpression  = rightExpression;
                rightExpression = tmp;
            }

            if (IsNull(rightExpression))
            {
                if (IsNull(leftExpression))
                {
                    throw new NotSupportedException();
                }

                left = ProjectionVisitor.CreateProjection(leftExpression);

                // If the restriction is applied to a component ("Component eq null"),
                // we should use Restrictions.IsNull(string propertyName) overload, otherwise NHibernate will raise an exception

                IPropertyProjection property = left as IPropertyProjection;

                if (property != null)
                {
                    switch (expression.Operator)
                    {
                    case Operator.Eq: return(Restrictions.IsNull(property.PropertyName));

                    case Operator.Ne: return(Restrictions.IsNotNull(property.PropertyName));
                    }
                }
                else
                {
                    switch (expression.Operator)
                    {
                    case Operator.Eq: return(Restrictions.IsNull(left));

                    case Operator.Ne: return(Restrictions.IsNotNull(left));
                    }
                }

                throw new NotSupportedException();
            }

            left  = ProjectionVisitor.CreateProjection(expression.Left);
            right = ProjectionVisitor.CreateProjection(expression.Right);

            switch (expression.Operator)
            {
            case Operator.Eq: return(Restrictions.EqProperty(left, right));

            case Operator.Ne: return(Restrictions.NotEqProperty(left, right));

            case Operator.Gt: return(Restrictions.GtProperty(left, right));

            case Operator.Ge: return(Restrictions.GeProperty(left, right));

            case Operator.Lt: return(Restrictions.LtProperty(left, right));

            case Operator.Le: return(Restrictions.LeProperty(left, right));

            default: throw new NotSupportedException();
            }
        }