Esempio n. 1
0
        public void ComplexTest_With_Substring()
        {
            var    oDataVisitor = new ODataVisitor();
            string model        = "X";
            Expression <Func <IQueryable <Car>, IEnumerable <Car> > > expression = (IQueryable <Car> data) =>
                                                                                   data.Where(x => x.Model.Substring(0, 1) == model);

            var result = oDataVisitor.Translate(expression);

            Console.WriteLine(result);
            Assert.AreEqual("$filter=(substring(Model,0,1) eq 'X')", result);
        }
        public void TopTest()
        {
            var oDataVisitor = new ODataVisitor();
            int count        = 50;
            Expression <Func <IQueryable <Car>, IEnumerable <Car> > > expression = (IQueryable <Car> data) =>
                                                                                   data.Take(50);

            var result = oDataVisitor.Translate(expression);

            Console.WriteLine(result);
            Assert.AreEqual("$top=50", result);
        }
        public void FilterTest_ORELSE()
        {
            var    oDataVisitor = new ODataVisitor();
            string name1        = "ali";
            Expression <Func <IQueryable <Car>, IEnumerable <Car> > > expression = (IQueryable <Car> data) =>
                                                                                   data.Where(x => x.Make == "Fiat" || x.MaxSpeed == 130);

            var result = oDataVisitor.Translate(expression);

            Console.WriteLine(result);
            Assert.AreEqual("$filter=((Make eq 'Fiat') OR (MaxSpeed eq 130))", result);
        }
Esempio n. 4
0
        public void ComplexTest()
        {
            var    oDataVisitor = new ODataVisitor();
            int    count        = 50;
            int    skip         = 20;
            string model        = "X3";
            Expression <Func <IQueryable <Car>, IEnumerable <Car> > > expression = (IQueryable <Car> data) =>
                                                                                   data.Where(x => x.Model == model).Skip(skip).Take(count);

            var result = oDataVisitor.Translate(expression);

            Console.WriteLine(result);
            Assert.AreEqual("$filter=(Model eq 'X3')&$skip=20&$top=50", result);
        }
Esempio n. 5
0
        public void ComplexTest_withOrdering_desc()
        {
            var    oDataVisitor = new ODataVisitor();
            int    count        = 50;
            int    skip         = 20;
            string model        = "X3";
            Expression <Func <IQueryable <Car>, IEnumerable <Car> > > expression = (IQueryable <Car> data) =>
                                                                                   data.Where(x => x.Model == model)
                                                                                   .Skip(skip)
                                                                                   .OrderByDescending(x => x.Price);

            var result = oDataVisitor.Translate(expression);

            Console.WriteLine(result);
            Assert.AreEqual("$filter=(Model eq 'X3')&$skip=20&$orderby=Price DESC", result);
        }
 protected override string GetQueryString(Expression expression)
 {
     var odataVisitor = new ODataVisitor();
     return odataVisitor.Translate(expression);
 }
Esempio n. 7
0
        protected override string GetQueryString(Expression expression)
        {
            var odataVisitor = new ODataVisitor();

            return(odataVisitor.Translate(expression));
        }