コード例 #1
0
        public void TwoMultiQueriesWithDifferentPagingGetDifferentResultsWhenUsingCachedQueries()
        {
            CreateItems();
            using (ISession s = OpenSession())
            {
                ICriteria criteria = s.CreateCriteria(typeof(Item))
                                     .Add(Expression.Gt("id", 50));
                IMultiCriteria multiCriteria = s.CreateMultiCriteria()
                                               .Add(CriteriaTransformer.Clone(criteria).SetFirstResult(10))
                                               .Add(CriteriaTransformer.Clone(criteria).SetProjection(Projections.RowCount()));
                multiCriteria.SetCacheable(true);
                IList results = multiCriteria.List();
                IList items   = (IList)results[0];
                Assert.AreEqual(89, items.Count);
                int count = (int)((IList)results[1])[0];
                Assert.AreEqual(99L, count);
            }

            using (ISession s = OpenSession())
            {
                ICriteria criteria = s.CreateCriteria(typeof(Item))
                                     .Add(Expression.Gt("id", 50));
                IMultiCriteria multiCriteria = s.CreateMultiCriteria()
                                               .Add(CriteriaTransformer.Clone(criteria).SetFirstResult(20))
                                               .Add(CriteriaTransformer.Clone(criteria).SetProjection(Projections.RowCount()));
                multiCriteria.SetCacheable(true);
                IList results = multiCriteria.List();
                IList items   = (IList)results[0];
                Assert.AreEqual(79, items.Count, "Should have gotten different result here, because the paging is different");
                int count = (int)((IList)results[1])[0];
                Assert.AreEqual(99L, count);
            }

            RemoveAllItems();
        }
コード例 #2
0
 private void DoMutiQueryAndAssert()
 {
     using (ISession s = OpenSession())
     {
         ICriteria criteria = s.CreateCriteria(typeof(Item))
                              .Add(Expression.Gt("id", 50));
         IMultiCriteria multiCriteria = s.CreateMultiCriteria()
                                        .Add(CriteriaTransformer.Clone(criteria).SetFirstResult(10))
                                        .Add(CriteriaTransformer.Clone(criteria).SetProjection(Projections.RowCount()));
         multiCriteria.SetCacheable(true);
         IList results = multiCriteria.List();
         IList items   = (IList)results[0];
         Assert.AreEqual(89, items.Count);
         int count = (int)((IList)results[1])[0];
         Assert.AreEqual(99L, count);
     }
 }
コード例 #3
0
        public void CanGetMultiQueryFromSecondLevelCache()
        {
            CreateItems();
            //set the query in the cache
            DoMutiQueryAndAssert();

            Hashtable cacheHashtable  = GetHashTableUsedAsQueryCache();
            IList     cachedListEntry = (IList) new ArrayList(cacheHashtable.Values)[0];
            IList     cachedQuery     = (IList)cachedListEntry[1];

            IList firstQueryResults = (IList)cachedQuery[0];

            firstQueryResults.Clear();
            firstQueryResults.Add(3);
            firstQueryResults.Add(4);

            IList secondQueryResults = (IList)cachedQuery[1];

            secondQueryResults[0] = 2;

            using (ISession s = sessions.OpenSession())
            {
                ICriteria criteria = s.CreateCriteria(typeof(Item))
                                     .Add(Expression.Gt("id", 50));
                IMultiCriteria multiCriteria = s.CreateMultiCriteria()
                                               .Add(CriteriaTransformer.Clone(criteria).SetFirstResult(10))
                                               .Add(CriteriaTransformer.Clone(criteria).SetProjection(Projections.RowCount()));
                multiCriteria.SetCacheable(true);
                IList results = multiCriteria.List();
                IList items   = (IList)results[0];
                Assert.AreEqual(2, items.Count);
                int count = (int)((IList)results[1])[0];
                Assert.AreEqual(2L, count);
            }

            RemoveAllItems();
        }