Example #1
0
        public void TestAllBuilderOverloads()
        {
            ICriteria expected = CreateSession()
                                 .CreateCriteria(typeof(Person))
                                 .Add(Subqueries.PropertyIn("Name", DetachedCriteriaSubquery))
                                 .Add(Subqueries.PropertyNotIn("Name", DetachedCriteriaSubquery))

                                 .Add(Subqueries.PropertyEq("Age", DetachedCriteriaSubquery))
                                 .Add(Subqueries.PropertyNe("Age", DetachedCriteriaSubquery))
                                 .Add(Subqueries.PropertyGt("Age", DetachedCriteriaSubquery))
                                 .Add(Subqueries.PropertyGe("Age", DetachedCriteriaSubquery))
                                 .Add(Subqueries.PropertyLt("Age", DetachedCriteriaSubquery))
                                 .Add(Subqueries.PropertyLe("Age", DetachedCriteriaSubquery))

                                 .Add(Subqueries.PropertyEqAll("Age", DetachedCriteriaSubquery))
                                 .Add(Subqueries.PropertyGtAll("Age", DetachedCriteriaSubquery))
                                 .Add(Subqueries.PropertyGeAll("Age", DetachedCriteriaSubquery))
                                 .Add(Subqueries.PropertyLtAll("Age", DetachedCriteriaSubquery))
                                 .Add(Subqueries.PropertyLeAll("Age", DetachedCriteriaSubquery))

                                 .Add(Subqueries.PropertyGtSome("Age", DetachedCriteriaSubquery))
                                 .Add(Subqueries.PropertyGeSome("Age", DetachedCriteriaSubquery))
                                 .Add(Subqueries.PropertyLtSome("Age", DetachedCriteriaSubquery))
                                 .Add(Subqueries.PropertyLeSome("Age", DetachedCriteriaSubquery));

            ICriteria actual = CreateSession()
                               .CreateCriteria(typeof(Person))
                               .Add(LambdaSubquery.Property <Person>(p => p.Name).In(DetachedCriteriaSubquery))
                               .Add(LambdaSubquery.Property <Person>(p => p.Name).NotIn(DetachedCriteriaSubquery))

                               .Add(LambdaSubquery.Property <Person>(p => p.Age).Eq(DetachedCriteriaSubquery))
                               .Add(LambdaSubquery.Property <Person>(p => p.Age).Ne(DetachedCriteriaSubquery))
                               .Add(LambdaSubquery.Property <Person>(p => p.Age).Gt(DetachedCriteriaSubquery))
                               .Add(LambdaSubquery.Property <Person>(p => p.Age).Ge(DetachedCriteriaSubquery))
                               .Add(LambdaSubquery.Property <Person>(p => p.Age).Lt(DetachedCriteriaSubquery))
                               .Add(LambdaSubquery.Property <Person>(p => p.Age).Le(DetachedCriteriaSubquery))

                               .Add(LambdaSubquery.Property <Person>(p => p.Age).EqAll(DetachedCriteriaSubquery))
                               .Add(LambdaSubquery.Property <Person>(p => p.Age).GtAll(DetachedCriteriaSubquery))
                               .Add(LambdaSubquery.Property <Person>(p => p.Age).GeAll(DetachedCriteriaSubquery))
                               .Add(LambdaSubquery.Property <Person>(p => p.Age).LtAll(DetachedCriteriaSubquery))
                               .Add(LambdaSubquery.Property <Person>(p => p.Age).LeAll(DetachedCriteriaSubquery))

                               .Add(LambdaSubquery.Property <Person>(p => p.Age).GtSome(DetachedCriteriaSubquery))
                               .Add(LambdaSubquery.Property <Person>(p => p.Age).GeSome(DetachedCriteriaSubquery))
                               .Add(LambdaSubquery.Property <Person>(p => p.Age).LtSome(DetachedCriteriaSubquery))
                               .Add(LambdaSubquery.Property <Person>(p => p.Age).LeSome(DetachedCriteriaSubquery));

            AssertCriteriaAreEqual(expected, actual);
        }
Example #2
0
        public void TestAllExpressionCombinations()
        {
            ICriteria expected = CreateSession()
                                 .CreateCriteria(typeof(Person), "personAlias")
                                 .Add(Subqueries.PropertyEq("personAlias.Age", DetachedCriteriaSubquery))
                                 .Add(Subqueries.PropertyNe("Age", DetachedCriteriaSubquery))
                                 .Add(Subqueries.PropertyGt("Age", DetachedCriteriaSubquery))
                                 .Add(Subqueries.PropertyGe("Age", DetachedCriteriaSubquery))
                                 .Add(Subqueries.PropertyLt("Age", DetachedCriteriaSubquery))
                                 .Add(Subqueries.PropertyLe("Age", DetachedCriteriaSubquery))

                                 .Add(Subqueries.PropertyEqAll("personAlias.Age", DetachedCriteriaSubquery))
                                 .Add(Subqueries.PropertyGtAll("Age", DetachedCriteriaSubquery))
                                 .Add(Subqueries.PropertyGeAll("Age", DetachedCriteriaSubquery))
                                 .Add(Subqueries.PropertyLtAll("Age", DetachedCriteriaSubquery))
                                 .Add(Subqueries.PropertyLeAll("Age", DetachedCriteriaSubquery))

                                 .Add(Subqueries.PropertyGtSome("personAlias.Age", DetachedCriteriaSubquery))
                                 .Add(Subqueries.PropertyGeSome("Age", DetachedCriteriaSubquery))
                                 .Add(Subqueries.PropertyLtSome("Age", DetachedCriteriaSubquery))
                                 .Add(Subqueries.PropertyLeSome("Age", DetachedCriteriaSubquery));

            Person    personAlias = null;
            ICriteria actual      = CreateSession()
                                    .CreateCriteria(typeof(Person), () => personAlias)
                                    .Add(LambdaSubquery.Where(() => personAlias.Age == DetachedCriteriaSubquery.As <int>()))
                                    .Add(LambdaSubquery.Where <Person>(p => p.Age != DetachedCriteriaSubquery.As <int>()))
                                    .Add(LambdaSubquery.Where <Person>(p => p.Age > DetachedCriteriaSubquery.As <int>()))
                                    .Add(LambdaSubquery.Where <Person>(p => p.Age >= DetachedCriteriaSubquery.As <int>()))
                                    .Add(LambdaSubquery.Where <Person>(p => p.Age < DetachedCriteriaSubquery.As <int>()))
                                    .Add(LambdaSubquery.Where <Person>(p => p.Age <= DetachedCriteriaSubquery.As <int>()))

                                    .Add(LambdaSubquery.WhereAll(() => personAlias.Age == DetachedCriteriaSubquery.As <int>()))
                                    .Add(LambdaSubquery.WhereAll <Person>(p => p.Age > DetachedCriteriaSubquery.As <int>()))
                                    .Add(LambdaSubquery.WhereAll <Person>(p => p.Age >= DetachedCriteriaSubquery.As <int>()))
                                    .Add(LambdaSubquery.WhereAll <Person>(p => p.Age < DetachedCriteriaSubquery.As <int>()))
                                    .Add(LambdaSubquery.WhereAll <Person>(p => p.Age <= DetachedCriteriaSubquery.As <int>()))

                                    .Add(LambdaSubquery.WhereSome(() => personAlias.Age > DetachedCriteriaSubquery.As <int>()))
                                    .Add(LambdaSubquery.WhereSome <Person>(p => p.Age >= DetachedCriteriaSubquery.As <int>()))
                                    .Add(LambdaSubquery.WhereSome <Person>(p => p.Age < DetachedCriteriaSubquery.As <int>()))
                                    .Add(LambdaSubquery.WhereSome <Person>(p => p.Age <= DetachedCriteriaSubquery.As <int>()));

            AssertCriteriaAreEqual(expected, actual);
        }
Example #3
0
        public void PropertyAsSomeSyntaxCrtierion()
        {
            ICriteria expected =
                CreateTestCriteria(typeof(Person))
                .Add(Subqueries.PropertyGeSome("Age", DetachedCriteriaAge))
                .Add(Subqueries.PropertyGtSome("Age", DetachedCriteriaAge))
                .Add(Subqueries.PropertyLeSome("Age", DetachedCriteriaAge))
                .Add(Subqueries.PropertyLtSome("Age", DetachedCriteriaAge));

            var actual =
                CreateTestQueryOver <Person>()
                .And(Subqueries.WhereSome <Person>(p => p.Age >= DetachedQueryOverAge.As <int>()))
                .And(Subqueries.WhereSome <Person>(p => p.Age > DetachedQueryOverAge.As <int>()))
                .And(Subqueries.WhereSome <Person>(p => p.Age <= DetachedQueryOverAge.As <int>()))
                .And(Subqueries.WhereSome <Person>(p => p.Age < DetachedQueryOverAge.As <int>()));

            AssertCriteriaAreEqual(expected, actual);
        }
Example #4
0
        public void PropertySomeCriterion()
        {
            ICriteria expected =
                CreateTestCriteria(typeof(Person))
                .Add(Subqueries.PropertyGeSome("Age", DetachedCriteriaAge))
                .Add(Subqueries.PropertyGtSome("Age", DetachedCriteriaAge))
                .Add(Subqueries.PropertyLeSome("Age", DetachedCriteriaAge))
                .Add(Subqueries.PropertyLtSome("Age", DetachedCriteriaAge));

            var actual =
                CreateTestQueryOver <Person>()
                .And(Subqueries.WhereProperty <Person>(p => p.Age).GeSome(DetachedQueryOverAge))
                .And(Subqueries.WhereProperty <Person>(p => p.Age).GtSome(DetachedQueryOverAge))
                .And(Subqueries.WhereProperty <Person>(p => p.Age).LeSome(DetachedQueryOverAge))
                .And(Subqueries.WhereProperty <Person>(p => p.Age).LtSome(DetachedQueryOverAge));

            AssertCriteriaAreEqual(expected, actual);
        }
Example #5
0
        public void SubqueriesExpressions()
        {
            DetachedCriteria dc = DetachedCriteria.For(typeof(Student))
                                  .Add(Expression.Eq("Name", "Gavin King"));
            ICriterion c = Subqueries.Eq("Gavin King", dc);

            NHAssert.IsSerializable(c);
            c = Subqueries.EqAll("Gavin King", dc);
            NHAssert.IsSerializable(c);
            c = Subqueries.Exists(dc);
            NHAssert.IsSerializable(c);
            c = Subqueries.Ge("Gavin King", dc);
            NHAssert.IsSerializable(c);
            c = Subqueries.GeAll("Gavin King", dc);
            NHAssert.IsSerializable(c);
            c = Subqueries.GeSome("Gavin King", dc);
            NHAssert.IsSerializable(c);
            c = Subqueries.Gt("Gavin King", dc);
            NHAssert.IsSerializable(c);
            c = Subqueries.GtAll("Gavin King", dc);
            NHAssert.IsSerializable(c);
            c = Subqueries.GtSome("Gavin King", dc);
            NHAssert.IsSerializable(c);
            c = Subqueries.In("Gavin King", dc);
            NHAssert.IsSerializable(c);
            c = Subqueries.Le("Gavin King", dc);
            NHAssert.IsSerializable(c);
            c = Subqueries.LeAll("Gavin King", dc);
            NHAssert.IsSerializable(c);
            c = Subqueries.LeSome("Gavin King", dc);
            NHAssert.IsSerializable(c);
            c = Subqueries.Lt("Gavin King", dc);
            NHAssert.IsSerializable(c);
            c = Subqueries.LtAll("Gavin King", dc);
            NHAssert.IsSerializable(c);
            c = Subqueries.LtSome("Gavin King", dc);
            NHAssert.IsSerializable(c);
            c = Subqueries.Ne("Gavin King", dc);
            NHAssert.IsSerializable(c);
            c = Subqueries.NotExists(dc);
            NHAssert.IsSerializable(c);
            c = Subqueries.NotIn("Gavin King", dc);
            NHAssert.IsSerializable(c);
            c = Subqueries.PropertyEq("Name", dc);
            NHAssert.IsSerializable(c);
            c = Subqueries.PropertyEqAll("Name", dc);
            NHAssert.IsSerializable(c);
            c = Subqueries.PropertyGe("Name", dc);
            NHAssert.IsSerializable(c);
            c = Subqueries.PropertyGeAll("Name", dc);
            NHAssert.IsSerializable(c);
            c = Subqueries.PropertyGeSome("Name", dc);
            NHAssert.IsSerializable(c);
            c = Subqueries.PropertyGt("Name", dc);
            NHAssert.IsSerializable(c);
            c = Subqueries.PropertyGtAll("Name", dc);
            NHAssert.IsSerializable(c);
            c = Subqueries.PropertyGtSome("Name", dc);
            NHAssert.IsSerializable(c);
            c = Subqueries.PropertyIn("Name", dc);
            NHAssert.IsSerializable(c);
            c = Subqueries.PropertyLe("Name", dc);
            NHAssert.IsSerializable(c);
            c = Subqueries.PropertyLeAll("Name", dc);
            NHAssert.IsSerializable(c);
            c = Subqueries.PropertyLeSome("Name", dc);
            NHAssert.IsSerializable(c);
            c = Subqueries.PropertyLt("Name", dc);
            NHAssert.IsSerializable(c);
            c = Subqueries.PropertyLtAll("Name", dc);
            NHAssert.IsSerializable(c);
            c = Subqueries.PropertyLtSome("Name", dc);
            NHAssert.IsSerializable(c);
            c = Subqueries.PropertyNe("Name", dc);
            NHAssert.IsSerializable(c);
            c = Subqueries.PropertyNotIn("Name", dc);
            NHAssert.IsSerializable(c);
        }