コード例 #1
0
        public void QueryWithInclude()
        {
            var users = Database.Query <User>().Include(x => x.House).ToList();

            InMemoryUsers.ForEach(x => x.House = InMemoryHouses.SingleOrDefault(y => y.HouseId == x.HouseId));

            Assert.AreEqual(15, users.Count);
            for (int i = 0; i < users.Count; i++)
            {
                AssertUserValues(InMemoryUsers[i], users[i]);
                AssertUserHouseValues(InMemoryUsers[i], users[i]);
            }
        }
コード例 #2
0
        public void QueryWithIncludeAndNestedOrderBy()
        {
            var users = Database.Query <User>().Include(x => x.House).Where(x => x.HouseId != null).OrderBy(x => x.House.Address).ToList();

            InMemoryUsers.ForEach(x => x.House = InMemoryHouses.SingleOrDefault(y => y.HouseId == x.HouseId));
            var inmemory = InMemoryUsers.Where(x => x.HouseId != null).OrderBy(x => x.House.Address).ToList();

            Assert.AreEqual(7, users.Count);
            for (int i = 0; i < users.Count; i++)
            {
                AssertUserValues(inmemory[i], users[i]);
                AssertUserHouseValues(inmemory[i], users[i]);
            }
        }
コード例 #3
0
        public void QueryWithIncludeNestedOrderByLimitAndProjection()
        {
            var users = Database.Query <User>()
                        .Include(x => x.House)
                        .Where(x => x.HouseId != null)
                        .OrderBy(x => x.House.HouseId)
                        .Limit(5)
                        .ProjectTo(x => new { Address = (x.HouseId != null ? x.House.Address : string.Empty), x.House.HouseId });

            InMemoryUsers.ForEach(x => x.House = InMemoryHouses.SingleOrDefault(y => y.HouseId == x.HouseId));
            var inmemory = InMemoryUsers.Where(x => x.HouseId != null).OrderBy(x => x.House.HouseId).Select(x => new { x.House.Address, x.HouseId }).ToList();

            Assert.AreEqual(5, users.Count);
            for (int i = 0; i < users.Count; i++)
            {
                Assert.AreEqual(inmemory[i].Address, users[i].Address);
                Assert.AreEqual(inmemory[i].HouseId, users[i].HouseId);
            }
        }
コード例 #4
0
        public void QueryWithIncludeNestedOrderByLimitAndProjectionToProjectUser()
        {
            var users = Database.Query <User>()
                        .Include(x => x.House)
                        .Where(x => x.HouseId != null)
                        .OrderBy(x => x.House.HouseId)
                        .Limit(5)
                        .ProjectTo(x => new ProjectUser()
            {
                NameWithAge = x.Name + x.Age
            });

            InMemoryUsers.ForEach(x => x.House = InMemoryHouses.SingleOrDefault(y => y.HouseId == x.HouseId));
            var inmemory = InMemoryUsers.Where(x => x.HouseId != null).OrderBy(x => x.House.HouseId).ToList();

            Assert.AreEqual(5, users.Count);
            for (int i = 0; i < users.Count; i++)
            {
                Assert.AreEqual(inmemory[i].Name + inmemory[i].Age, users[i].NameWithAge);
            }
        }