Esempio n. 1
0
 public async Task CanMinProjectionOnIdentityProjectionAsync()
 {
     using (ISession s = OpenSession())
     {
         ISQLFunction arithmaticAddition = new VarArgsSQLFunction("(", "+", ")");
         ICriteria    c =
             s.CreateCriteria(typeof(Person)).SetProjection(
                 Projections.Min(Projections.SqlFunction(arithmaticAddition, NHibernateUtil.GuessType(typeof(double)),
                                                         Projections.Property("IQ"), Projections.Property("ShoeSize"))));
         IList list = await(c.ListAsync());
         Assert.AreEqual(19, list[0]);
     }
 }
Esempio n. 2
0
 public void CanAvgProjectionOnSqlFunction()
 {
     using (ISession s = OpenSession())
     {
         ISQLFunction arithmaticAddition = new VarArgsSQLFunction("(", "+", ")");
         ICriteria    c =
             s.CreateCriteria(typeof(Person)).SetProjection(
                 Projections.Avg(Projections.SqlFunction(arithmaticAddition, NHibernateUtil.GuessType(typeof(double)),
                                                         Projections.Property("IQ"), Projections.Property("ShoeSize"))));
         IList list = c.List();
         Assert.AreEqual(((double)334) / 5, list[0]);
     }
 }
Esempio n. 3
0
        public async Task OrderProjectionTestAsync()
        {
            ISQLFunction arithmaticMultiplication = new VarArgsSQLFunction("(", "*", ")");

            using (ISession session = this.OpenSession()) {
                ICriteria criteria = session.CreateCriteria(typeof(Person), "c");

                criteria.AddOrder(Order.Asc(
                                      Projections.SqlFunction(arithmaticMultiplication, NHibernateUtil.GuessType(typeof(int)),
                                                              Projections.Property("IQ"), Projections.Constant(-1))));
                IList <Person> results = await(criteria.ListAsync <Person>());
                Assert.AreEqual(5, results.Count);
                Assert.AreEqual("Sally", results[0].Name);
                Assert.AreEqual("Joe", results[4].Name);
            }
        }
Esempio n. 4
0
        public void CanOrderBySqlProjectionDesc()
        {
            using (ISession s = OpenSession())
            {
                ISQLFunction arithmaticAddition = new VarArgsSQLFunction("(", "+", ")");
                ICriteria    c =
                    s.CreateCriteria(typeof(Person)).AddOrder(
                        Order.Desc(Projections.SqlFunction(arithmaticAddition, NHibernateUtil.GuessType(typeof(double)),
                                                           Projections.Property("IQ"), Projections.Property("ShoeSize"))));
                IList <Person> list = c.List <Person>();

                for (int i = 0; i < list.Count - 1; i++)
                {
                    Assert.IsTrue(list[i].IQ + list[i].ShoeSize >= list[i + 1].IQ + list[i + 1].ShoeSize);
                }
            }
        }
Esempio n. 5
0
        public void VarArgsFunction()
        {
            IList args = new ArrayList();

            VarArgsSQLFunction vf = new VarArgsSQLFunction("(", " || ", ")");

            Assert.AreEqual("()", vf.Render(args, factoryImpl).ToString());

            args.Add("va1");
            Assert.AreEqual("(va1)", vf.Render(args, factoryImpl).ToString());

            args.Clear();
            args.Add("va1");
            args.Add("va2");
            args.Add("va3");
            Assert.AreEqual("(va1 || va2 || va3)", vf.Render(args, factoryImpl).ToString());
        }
Esempio n. 6
0
        public static IProjection ProcessOperator(MethodCallExpression methodCallExpression, string op)
        {
            var expressions = new List <Expression>();

            if (methodCallExpression.Object != null)
            {
                expressions.Add(methodCallExpression.Object);
            }

            foreach (var argumentExpression in methodCallExpression.Arguments)
            {
                expressions.Add(argumentExpression);
            }

            var sqlFunction = new VarArgsSQLFunction("(", op, ")");
            var returnType  = TypeUtil.GuessType(expressions[0].Type);
            var projections = expressions.Select(e => FindMemberProjection(e)).ToArray();

            return(Projections.SqlFunction(sqlFunction, returnType, projections));
        }
 private static void RegisterBinaryArithmeticExpression(ExpressionType type, string sqlOperand)
 {
     _binaryArithmethicTemplates[type] = new VarArgsSQLFunction("(", sqlOperand, ")");
 }