コード例 #1
0
        public void GroupByStructureFieldTest()
        {
            using (var session = Domain.OpenSession())
                using (var logger = new QueryLogger(session))
                    using (var transaction = session.OpenTransaction()) {
                        var expectedCounts = Query.All <Product>()
                                             .GroupBy(g => g.Price)
                                             .AsEnumerable()
                                             .Select(g => new { g.Key, Cnt = g.Count() })
                                             .ToList();

                        using (logger.Attach()) {
                            var x = Query.All <Product>()
                                    .GroupBy(g => g.Price)
                                    .Select(g => new { g.Key, Cnt = g.Count() });

                            foreach (var e in x)
                            {
                                var entry = expectedCounts.FirstOrDefault(i => i.Key == e.Key);
                                Assert.That(entry, Is.Not.Null);
                                Assert.That(e.Cnt, Is.EqualTo(entry.Cnt));
                            }
                        }
                    }
        }
コード例 #2
0
        public void GroupByAnonymousTypeWithPersistentAndNonNullableFielsTest()
        {
            using (var session = Domain.OpenSession())
                using (var logger = new QueryLogger(session))
                    using (var transaction = session.OpenTransaction()) {
                        var expectedCounts = Query.All <Product>()
                                             .GroupBy(g => new { Battery = g.Battery, Description = g.Name })
                                             .AsEnumerable()
                                             .Select(
                            g => new {
                            g.Key,
                            Cnt = g.Count()
                        })
                                             .ToList();

                        using (logger.Attach()) {
                            var x = Query.All <Product>()
                                    .GroupBy(g => new { Battery = g.Battery, Description = g.Name })
                                    .Select(g => new { g.Key, Cnt = g.Count() });

                            foreach (var e in x)
                            {
                                var entry = expectedCounts.FirstOrDefault(i => i.Key.Battery == e.Key.Battery && i.Key.Description == e.Key.Description);
                                Assert.That(entry, Is.Not.Null);
                                Assert.That(e.Cnt, Is.EqualTo(entry.Cnt));
                            }
                        }
                    }
        }