public void include_is_running_through_identitymap()
        {
            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();

            // This will only work with a non-NulloIdentityMap
            using (var query = theStore.OpenSession())
            {
                var dict = new Dictionary <Guid, User>();

                query.Query <Issue>().Include(x => x.AssigneeId, dict).ToArray();

                query.Load <User>(user1.Id).ShouldBeSameAs(dict[user1.Id]);
                query.Load <User>(user2.Id).ShouldBeSameAs(dict[user2.Id]);
            }
        }
        public async Task include_to_dictionary_async()
        {
            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);
            await theSession.SaveChangesAsync();

            using (var query = theStore.QuerySession())
            {
                var dict = new Dictionary <Guid, User>();

                await query.Query <Issue>().Include(x => x.AssigneeId, dict).ToListAsync();

                dict.Count.ShouldBe(2);
                dict.ContainsKey(user1.Id).ShouldBeTrue();
                dict.ContainsKey(user2.Id).ShouldBeTrue();
            }
        }
        public async Task include_to_list_with_orderby_ascending_async()
        {
            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);
            await theSession.SaveChangesAsync();

            using (var query = theStore.QuerySession())
            {
                var list = new List <User>();

                await query.Query <Issue>().Include(x => x.AssigneeId, list)
                .OrderBy(x => x.Id)
                .ToListAsync();

                list.Count.ShouldBe(2);

                list.Any(x => x.Id == user1.Id);
                list.Any(x => x.Id == user2.Id);
            }
        }
Example #4
0
        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);
            }
        }
Example #5
0
        public void compiled_include_to_dictionary()
        {
            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())
            {
                session.Logger = new TestOutputMartenLogger(_output);

                var query = new IssueWithUsersById();

                var issues = session.Query(query).ToArray();

                issues.ShouldNotBeEmpty();

                query.UsersById.Count.ShouldBe(2);
                query.UsersById.ContainsKey(user1.Id).ShouldBeTrue();
                query.UsersById.ContainsKey(user2.Id).ShouldBeTrue();
            }
        }
        public void multiple_includes()
        {
            var assignee = new User();
            var reporter = new User();

            var issue1 = new Issue {
                AssigneeId = assignee.Id, ReporterId = reporter.Id, Title = "Garage Door is busted"
            };

            theSession.Store(assignee, reporter);
            theSession.Store(issue1);
            theSession.SaveChanges();

            using (var query = theStore.QuerySession())
            {
                User assignee2 = null;
                User reporter2 = null;

                query
                .Query <Issue>()
                .Include <User>(x => x.AssigneeId, x => assignee2 = x)
                .Include <User>(x => x.ReporterId, x => reporter2 = x).Single()
                .ShouldNotBeNull();

                assignee2.Id.ShouldBe(assignee.Id);
                reporter2.Id.ShouldBe(reporter.Id);
            }
        }
Example #7
0
        public void compiled_query_with_multi_includes()
        {
            var user     = new User();
            var reporter = new User();
            var issue    = new Issue {
                AssigneeId = user.Id, ReporterId = reporter.Id, Title = "Garage Door is busted"
            };

            theSession.Store <object>(user, reporter, issue);
            theSession.SaveChanges();

            using (var query = theStore.QuerySession())
            {
                var issueQuery = new IssueByTitleIncludingUsers {
                    Title = issue.Title
                };
                var issue2 = query.Query(issueQuery);

                issueQuery.IncludedAssignee.ShouldNotBeNull();
                issueQuery.IncludedAssignee.Id.ShouldBe(user.Id);
                issueQuery.IncludedReported.ShouldNotBeNull();
                issueQuery.IncludedReported.Id.ShouldBe(reporter.Id);

                issue2.ShouldNotBeNull();
            }
        }
        public void 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 query = theStore.QuerySession())
            {
                var list = new List <User>();

                query.Query <Issue>().Include <User>(x => x.AssigneeId, list).ToArray();

                list.Count.ShouldBe(2);

                list.Any(x => x.Id == user1.Id);
                list.Any(x => x.Id == user2.Id);
            }
        }
Example #9
0
        // SAMPLE: deletes
        public void delete_documents(IDocumentSession session)
        {
            var user = new User();

            session.Delete(user);
            session.SaveChanges();

            // OR

            session.Delete(user.Id);
            session.SaveChanges();
        }
Example #10
0
        // SAMPLE: deletes
        public void delete_documents(IDocumentSession session)
        {
            var user = new User();

            session.Delete(user);
            session.SaveChanges();

            // OR

            session.Delete(user.Id);
            session.SaveChanges();
        } 
Example #11
0
        // SAMPLE: using-identity-map
        public void using_identity_map()
        {
            var user = new User {
                FirstName = "Tamba", LastName = "Hali"
            };

            theStore.BulkInsert(new [] { user });

            // Open a document session with the identity map
            using (var session = theStore.OpenSession())
            {
                session.Load <User>(user.Id)
                .ShouldBeTheSameAs(session.Load <User>(user.Id));
            }
        }
Example #12
0
        // SAMPLE: using-identity-map
        public void using_identity_map()
        {
            var container = Container.For<DevelopmentModeRegistry>();
            var store = container.GetInstance<IDocumentStore>();

            var user = new User {FirstName = "Tamba", LastName = "Hali"};
            store.BulkInsert(new [] {user});

            // Open a document session with the identity map
            using (var session = store.OpenSession())
            {
                session.Load<User>(user.Id)
                    .ShouldBeTheSameAs(session.Load<User>(user.Id));
            }
        } 
Example #13
0
        // SAMPLE: using-identity-map
        public void using_identity_map()
        {
            var container = Container.For <DevelopmentModeRegistry>();
            var store     = container.GetInstance <IDocumentStore>();

            var user = new User {
                FirstName = "Tamba", LastName = "Hali"
            };

            store.BulkInsert(new [] { user });

            // Open a document session with the identity map
            using (var session = store.OpenSession())
            {
                session.Load <User>(user.Id)
                .ShouldBeTheSameAs(session.Load <User>(user.Id));
            }
        }
        public void simple_include_for_a_single_document_using_outer_join()
        {
            var issue = new Issue {
                AssigneeId = null, Title = "Garage Door is busted"
            };

            theSession.Store(issue);
            theSession.SaveChanges();

            using (var query = theStore.QuerySession())
            {
                User included = null;
                var  issue2   = query.Query <Issue>()
                                .Include <User>(x => x.AssigneeId, x => included = x, JoinType.LeftOuter)
                                .Where(x => x.Title == issue.Title)
                                .Single();

                included.ShouldBeNull();

                issue2.ShouldNotBeNull();
            }
        }
Example #15
0
        public void simple_compiled_include_for_a_single_document()
        {
            var user  = new User();
            var issue = new Issue {
                AssigneeId = user.Id, Title = "Garage Door is busted"
            };

            theSession.Store <object>(user, issue);
            theSession.SaveChanges();

            using (var query = theStore.QuerySession())
            {
                var issueQuery = new IssueByTitleWithAssignee {
                    Title = issue.Title
                };
                var issue2 = query.Query(issueQuery);

                SpecificationExtensions.ShouldNotBeNull(issueQuery.Included);
                issueQuery.Included.Single().Id.ShouldBe(user.Id);

                SpecificationExtensions.ShouldNotBeNull(issue2);
            }
        }
        public void include_to_list_using_outer_join()
        {
            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"
            };
            var issue4 = new Issue {
                AssigneeId = null, Title = "Garage Door is busted"
            };

            theSession.Store(user1, user2);
            theSession.Store(issue1, issue2, issue3, issue4);
            theSession.SaveChanges();

            using (var query = theStore.QuerySession())
            {
                var list = new List <User>();

                var issues = query.Query <Issue>().Include <User>(x => x.AssigneeId, list, JoinType.LeftOuter).ToArray();

                list.Count.ShouldBe(3);

                list.Any(x => x.Id == user1.Id);
                list.Any(x => x.Id == user2.Id);
                list.Any(x => x == null);

                issues.Length.ShouldBe(4);
            }
        }
        public void simple_include_for_a_single_document()
        {
            var user  = new User();
            var issue = new Issue {
                AssigneeId = user.Id, Title = "Garage Door is busted"
            };

            theSession.Store <object>(user, issue);
            theSession.SaveChanges();

            using (var query = theStore.QuerySession())
            {
                User included = null;
                var  issue2   = query.Query <Issue>()
                                .Include <User>(x => x.AssigneeId, x => included = x)
                                .Where(x => x.Title == issue.Title)
                                .Single();

                included.ShouldNotBeNull();
                included.Id.ShouldBe(user.Id);

                issue2.ShouldNotBeNull();
            }
        }
        public void include_with_any_containment_where_for_a_single_document()
        {
            var user  = new User();
            var issue = new Issue {
                AssigneeId = user.Id, Tags = new [] { "DIY" }, Title = "Garage Door is busted"
            };

            theSession.Store <object>(user, issue);
            theSession.SaveChanges();

            using (var query = theStore.QuerySession())
            {
                User included = null;
                var  issue2   = query.Query <Issue>()
                                .Include <User>(x => x.AssigneeId, x => included = x)
                                .Where(x => x.Tags.Any(t => t == "DIY"))
                                .Single();

                included.ShouldNotBeNull();
                included.Id.ShouldBe(user.Id);

                issue2.ShouldNotBeNull();
            }
        }
        public async Task include_within_batch_query()
        {
            var user1 = new User();
            var user2 = new User();

            var issue1 = new Issue {
                AssigneeId = user1.Id, Title = "Garage Door is busted #1"
            };
            var issue2 = new Issue {
                AssigneeId = user2.Id, Title = "Garage Door is busted #2"
            };
            var issue3 = new Issue {
                AssigneeId = user2.Id, Title = "Garage Door is busted #3"
            };

            theSession.Store(user1, user2);
            theSession.Store(issue1, issue2, issue3);
            theSession.SaveChanges();

            using (var query = theStore.QuerySession())
            {
                User included = null;
                var  list     = new List <User>();
                var  dict     = new Dictionary <Guid, User>();

                // SAMPLE: batch_include
                var batch = query.CreateBatchQuery();

                var found = batch.Query <Issue>()
                            .Include <User>(x => x.AssigneeId, x => included = x)
                            .Where(x => x.Title == issue1.Title)
                            .Single();
                // ENDSAMPLE

                var toList = batch.Query <Issue>()
                             .Include <User>(x => x.AssigneeId, list).ToList();

                var toDict = batch.Query <Issue>()
                             .Include(x => x.AssigneeId, dict).ToList();

                await batch.Execute();


                (await found).Id.ShouldBe(issue1.Id);

                included.ShouldNotBeNull();
                included.Id.ShouldBe(user1.Id);

                (await toList).Count.ShouldBe(3);

                list.Count.ShouldBe(2); // Only 2 users


                (await toDict).Count.ShouldBe(3);

                dict.Count.ShouldBe(2);

                dict.ContainsKey(user1.Id).ShouldBeTrue();
                dict.ContainsKey(user2.Id).ShouldBeTrue();
            }
        }