예제 #1
0
        public void ValueCriterion()
        {
            ICriteria expected =
                CreateTestCriteria(typeof(Person))
                .Add(Subqueries.Eq("Name", DetachedCriteriaName))
                .Add(Subqueries.Ge("Age", DetachedCriteriaAge))
                .Add(Subqueries.Gt("Age", DetachedCriteriaAge))
                .Add(Subqueries.In("Name", DetachedCriteriaName))
                .Add(Subqueries.Le("Age", DetachedCriteriaAge))
                .Add(Subqueries.Lt("Age", DetachedCriteriaAge))
                .Add(Subqueries.Ne("Name", DetachedCriteriaName))
                .Add(Subqueries.NotIn("Name", DetachedCriteriaName));

            var actual =
                CreateTestQueryOver <Person>()
                .And(Subqueries.WhereValue("Name").Eq(DetachedQueryOverName))
                .And(Subqueries.WhereValue("Age").Ge(DetachedQueryOverAge))
                .And(Subqueries.WhereValue("Age").Gt(DetachedQueryOverAge))
                .And(Subqueries.WhereValue("Name").In(DetachedQueryOverName))
                .And(Subqueries.WhereValue("Age").Le(DetachedQueryOverAge))
                .And(Subqueries.WhereValue("Age").Lt(DetachedQueryOverAge))
                .And(Subqueries.WhereValue("Name").Ne(DetachedQueryOverName))
                .And(Subqueries.WhereValue("Name").NotIn(DetachedQueryOverName));

            AssertCriteriaAreEqual(expected, actual);
        }
예제 #2
0
        public List <AicraftInfoAndIfRegisteredBoolDto> GetAicraftInfoAndIfRegisteredBoolDto()
        {
            using (ITransaction transaction = session.BeginTransaction())
            {
                List <AicraftInfoAndIfRegisteredBoolDto> results = null;
                AicraftInfoAndIfRegisteredBoolDto        DTO     = null;
                AircraftRegistry aircraftRegistryAlias           = null;
                Aircraft         aircraftAlias = null;

                var projection = Projections.Conditional(
                    Subqueries.Gt(0, QueryOver.Of <AircraftRegistry>(() => aircraftRegistryAlias)
                                  .Where(ar => aircraftRegistryAlias.SerialNumber == aircraftAlias.SerialNumber)
                                  .SelectList(list => list
                                              .SelectCount(() => aircraftRegistryAlias.SerialNumber)).DetachedCriteria)       // this is the SUB-SELECT
                    , Projections.Constant(true, NHibernateUtil.Boolean)
                    , Projections.Constant(false, NHibernateUtil.Boolean)
                    );


                results = session.QueryOver <Aircraft>(() => aircraftAlias)
                          .WithSubquery
                          .WhereExists(QueryOver.Of <AircraftRegistry>(() => aircraftRegistryAlias)
                                       .Where(ar => aircraftRegistryAlias.SerialNumber == aircraftAlias.SerialNumber)
                                       .Select(Projections.Property(() => aircraftRegistryAlias.SerialNumber)))
                          .SelectList(selectionList => selectionList
                                      .Select(() => aircraftAlias.IsOperational).WithAlias(() => DTO.IsOperational)
                                      .Select(() => aircraftAlias.SerialNumber).WithAlias(() => DTO.SerialNumber)
                                      .Select(() => aircraftAlias.Vne).WithAlias(() => DTO.Vne)
                                      .Select(() => aircraftAlias.Manufacturer).WithAlias(() => DTO.Manufacturer)
                                      .Select(() => aircraftAlias.Model).WithAlias(() => DTO.Model)
                                      .Select(() => aircraftAlias.MaxTakeoffWeight).WithAlias(() => DTO.MaxTakeoffWeight)
                                      .Select(() => true).WithAlias(() => DTO.IsRegistered))
                          .TransformUsing(Transformers.AliasToBean <AicraftInfoAndIfRegisteredBoolDto>())
                          .List <AicraftInfoAndIfRegisteredBoolDto>().ToList();

                results.AddRange(session.QueryOver <Aircraft>(() => aircraftAlias)
                                 .WithSubquery
                                 .WhereNotExists(QueryOver.Of <AircraftRegistry>(() => aircraftRegistryAlias)
                                                 .Where(ar => aircraftRegistryAlias.SerialNumber == aircraftAlias.SerialNumber)
                                                 .Select(Projections.Property(() => aircraftRegistryAlias.SerialNumber)))
                                 .SelectList(selectionList => selectionList
                                             .Select(() => aircraftAlias.IsOperational).WithAlias(() => DTO.IsOperational)
                                             .Select(() => aircraftAlias.SerialNumber).WithAlias(() => DTO.SerialNumber)
                                             .Select(() => aircraftAlias.Vne).WithAlias(() => DTO.Vne)
                                             .Select(() => aircraftAlias.Manufacturer).WithAlias(() => DTO.Manufacturer)
                                             .Select(() => aircraftAlias.Model).WithAlias(() => DTO.Model)
                                             .Select(() => aircraftAlias.MaxTakeoffWeight).WithAlias(() => DTO.MaxTakeoffWeight)
                                             .Select(() => false).WithAlias(() => DTO.IsRegistered))
                                 .TransformUsing(Transformers.AliasToBean <AicraftInfoAndIfRegisteredBoolDto>())
                                 .List <AicraftInfoAndIfRegisteredBoolDto>().ToList());



                transaction.Commit();
                return(results);
            }
        }
예제 #3
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);
        }