Example #1
0
        public void distinct_and_count_long()
        {
            var product1 = new ProductWithList {
                Tags = new List <string> {
                    "a", "b", "c"
                }
            };
            var product2 = new ProductWithList {
                Tags = new List <string> {
                    "b", "c", "d"
                }
            };
            var product3 = new ProductWithList {
                Tags = new List <string> {
                    "d", "e", "f"
                }
            };

            using (var session = theStore.OpenSession())
            {
                session.Store(product1, product2, product3);
                session.SaveChanges();
            }

            using (var query = theStore.QuerySession())
            {
                query
                .Query <ProductWithList>()
                .SelectMany(x => x.Tags)
                .Distinct()
                .LongCount()
                .ShouldBe(6L);
            }
        }
Example #2
0
        public void can_do_simple_select_many_against_generic_list()
        {
            var product1 = new ProductWithList {
                Tags = new List <string> {
                    "a", "b", "c"
                }
            };
            var product2 = new ProductWithList {
                Tags = new List <string> {
                    "b", "c", "d"
                }
            };
            var product3 = new ProductWithList {
                Tags = new List <string> {
                    "d", "e", "f"
                }
            };

            using (var session = theStore.OpenSession())
            {
                session.Store(product1, product2, product3);
                session.SaveChanges();
            }

            using (var query = theStore.QuerySession())
            {
                var distinct = query.Query <ProductWithList>().SelectMany(x => x.Tags).Distinct().ToList();

                distinct.OrderBy(x => x).ShouldHaveTheSameElementsAs("a", "b", "c", "d", "e", "f");

                var names = query.Query <ProductWithList>().SelectMany(x => x.Tags).ToList();
                names
                .Count().ShouldBe(9);
            }
        }