public void compiled_include_to_list() { var user1 = new User(); var user2 = new User(); var issue1 = new Issue { AssigneeId = user1.Id, Title = "Garage Door is busted" }; var issue2 = new Issue { AssigneeId = user2.Id, Title = "Garage Door is busted" }; var issue3 = new Issue { AssigneeId = user2.Id, Title = "Garage Door is busted" }; theSession.Store(user1, user2); theSession.Store(issue1, issue2, issue3); theSession.SaveChanges(); using (var session = theStore.QuerySession()) { var query = new IssueWithUsers(); var issues = session.Query(query).ToArray(); query.Users.Count.ShouldBe(2); issues.Count().ShouldBe(3); query.Users.Any(x => x.Id == user1.Id); query.Users.Any(x => x.Id == user2.Id); } }
public void can_get_includes_with_compiled_queries() { var user1 = new User(); var user2 = new User(); var issue1 = new Issue { AssigneeId = user1.Id, Title = "Garage Door is busted" }; var issue2 = new Issue { AssigneeId = user2.Id, Title = "Garage Door is busted" }; var issue3 = new Issue { AssigneeId = user2.Id, Title = "Garage Door is busted" }; theSession.Store(user1, user2); theSession.Store(issue1, issue2, issue3); theSession.SaveChanges(); // Issue first query using (var session = theStore.QuerySession()) { var query = new IssueWithUsers(); var issues = session.Query(query).ToArray(); query.Users.Count.ShouldBe(2); issues.Count().ShouldBe(3); query.Users.Any(x => x.Id == user1.Id).ShouldBeTrue(); query.Users.Any(x => x.Id == user2.Id).ShouldBeTrue(); } // Issue second query using (var session = theStore.QuerySession()) { var query = new IssueWithUsers(); var issues = session.Query(query).ToArray(); // Should populate this instance of IssueWithUsers query.Users.ShouldNotBeNull(); // Should not re-use a previous instance of IssueWithUsers, which would make the count 4 query.Users.Count.ShouldBe(2); issues.Count().ShouldBe(3); query.Users.Any(x => x.Id == user1.Id); query.Users.Any(x => x.Id == user2.Id); } }