Beispiel #1
0
        public void include_with_any_containment_where_for_a_single_document_with_snake_casing()
        {
            StoreOptions(_ => _.UseDefaultSerialization(casing: Casing.SnakeCase));

            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();
            }
        }
Beispiel #2
0
        public void Bug_1751_Include_with_select()
        {
            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)
                                .Select(x => new IssueDTO {
                    Id = x.Id, AssigneeId = x.AssigneeId
                })
                                .Single();

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

                issue2.ShouldNotBeNull();
            }
        }
Beispiel #3
0
        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);
            await theSession.SaveChangesAsync();

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

                #region 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();
                #endregion sample_batch_include

                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();

            }
        }
Beispiel #4
0
        public void include_with_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)
                    .Single(x => Enumerable.Contains(x.Tags, "DIY"));

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

                issue2.ShouldNotBeNull();
            }
        }
Beispiel #5
0
        public async Task Bug_1715_simple_include_for_a_single_document_async()
        {
            theSession.Logger = new TestOutputMartenLogger(_output);

            var user = new User();
            var bug = new Bug();

            theSession.Store(user);
            theSession.Store(bug);

            var issue = new Issue
            {
                AssigneeId = user.Id, Title = "Garage Door is busted", BugId = bug.Id
            };

            theSession.Store(issue);

            await theSession.SaveChangesAsync();

            using (var query = theStore.QuerySession())
            {
                User includedUser = null;
                Bug includedBug = null;
                var issue2 = await query.Query<Issue>()
                    .Include<User>(x => x.AssigneeId, x => includedUser = x)
                    .Include<Bug>(x => x.BugId, x => includedBug = x)
                    .Where(x => x.Title == issue.Title)
                    .SingleAsync();

                includedUser.ShouldNotBeNull();
                includedBug.ShouldNotBeNull();
                includedUser.Id.ShouldBe(user.Id);
                includedBug.Id.ShouldBe(bug.Id);

                issue2.ShouldNotBeNull();
            }
        }
Beispiel #6
0
        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();
            }
        }