Exemplo n.º 1
0
 public void JoinTablesWithGuidKeysShouldBeProperlyInserted()
 {
     using (var db = new BlogContext())
     {
         var blog = new Blog {
             Name = "My Blog"
         };
         var firstPost = new Post
         {
             Blog = blog,
             Text = "My first blogpost.",
         };
         var visitor = new Visitor
         {
             Name = "Visitor1"
         };
         firstPost.Visitors.Add(visitor);
         var req = new BulkInsertRequest <Post>
         {
             Entities = new[] { firstPost }.ToList(),
             AllowNotNullSelfReferences = AllowNotNullSelfReferences.No,
             SortUsingClusteredIndex    = true,
             EnableRecursiveInsert      = EnableRecursiveInsert.Yes
         };
         var response = db.BulkInsertAll(req);
         var posts    = db.Posts
                        .Include(p => p.Blog)
                        .ToArray();
         Assert.AreEqual(1, posts.Count());
     }
 }
Exemplo n.º 2
0
        public void ModifiedEntityShouldBeUpdated()
        {
            using (var db = new BlogContext())
            {
                var blog = new Blog {
                    Name = "My Blog"
                };
                var firstPost = new Post
                {
                    Text         = "My first blogpost.",
                    PostKeywords = new List <Keyword>()
                    {
                        new Keyword {
                            Text = "first"
                        }
                    }
                };
                var secondPost = new Post
                {
                    Text         = "My second blogpost.",
                    PostKeywords = new List <Keyword>()
                    {
                        new Keyword {
                            Text = "second"
                        }
                    }
                };
                blog.BlogPosts.Add(firstPost);
                blog.BlogPosts.Add(secondPost);
                var req = new BulkInsertRequest <Blog>
                {
                    Entities = new[] { blog }.ToList(),
                    AllowNotNullSelfReferences = false,
                    SortUsingClusteredIndex    = true,
                    Recursive = true
                };
                var response = db.BulkInsertAll(req);

                var b = db.Blogs.Single();
                Assert.AreEqual("My Blog", b.Name);

                b.Name = "My (modified) Blog";
                db.BulkUpdateAll(new BulkUpdateRequest
                {
                    Entities         = new [] { b },
                    KeyPropertyNames = new [] { "Id" }
                });

                b = db.Blogs.Single();
                Assert.AreEqual("My (modified) Blog", b.Name);
            }
        }
Exemplo n.º 3
0
 public void OneToManyWithGuidPrimaryKeyInsertingTheTopEntity()
 {
     using (var db = new BlogContext())
     {
         var blog = new Blog {
             Name = "My Blog"
         };
         var firstPost = new Post
         {
             Text         = "My first blogpost.",
             PostKeywords = new List <Keyword>()
             {
                 new Keyword {
                     Text = "first"
                 }
             }
         };
         var secondPost = new Post
         {
             Text         = "My second blogpost.",
             PostKeywords = new List <Keyword>()
             {
                 new Keyword {
                     Text = "second"
                 }
             }
         };
         blog.BlogPosts.Add(firstPost);
         blog.BlogPosts.Add(secondPost);
         var req = new BulkInsertRequest <Blog>
         {
             Entities = new[] { blog }.ToList(),
             AllowNotNullSelfReferences = AllowNotNullSelfReferences.No,
             SortUsingClusteredIndex    = true,
             EnableRecursiveInsert      = EnableRecursiveInsert.Yes
         };
         var response = db.BulkInsertAll(req);
         var posts    = db.Posts
                        .Include(p => p.Blog)
                        .ToArray();
         Assert.AreEqual(2, posts.Count());
         Assert.AreEqual(posts[1].Blog, posts[0].Blog);
     }
 }
Exemplo n.º 4
0
 public void OneToManyWithGuidPrimaryKeyInsertingTheChildEntities()
 {
     using (var db = new BlogContext())
     {
         var blog = new Blog {
             Name = "My Blog"
         };
         var firstPost = new Post
         {
             Blog         = blog,
             Text         = "My first blogpost.",
             PostKeywords = new List <Keyword>()
             {
                 new Keyword {
                     Text = "first"
                 }
             }
         };
         var secondPost = new Post
         {
             Blog         = blog,
             Text         = "My second blogpost.",
             PostKeywords = new List <Keyword>()
             {
                 new Keyword {
                     Text = "second"
                 }
             }
         };
         var req = new BulkInsertRequest <Post>
         {
             Entities = new[] { firstPost, secondPost }.ToList(),
             AllowNotNullSelfReferences = false,
             SortUsingClusteredIndex    = true,
             Recursive = true
         };
         var response = db.BulkInsertAll(req);
         var posts    = db.Posts
                        .Include(p => p.Blog)
                        .ToArray();
         Assert.AreEqual(2, posts.Count());
         Assert.AreEqual(posts[1].Blog, posts[0].Blog);
     }
 }
 public void OneToManyWithGuidPrimaryKey()
 {
     using (var db = new BlogContext())
     {
         var blog = new Blog {
             Name = "My Blog"
         };
         var firstPost = new Post
         {
             Blog         = blog,
             Text         = "My first blogpost.",
             PostKeywords = new List <Keyword>()
             {
                 new Keyword {
                     Text = "first"
                 }
             }
         };
         var secondPost = new Post
         {
             Blog         = blog,
             Text         = "My second blogpost.",
             PostKeywords = new List <Keyword>()
             {
                 new Keyword {
                     Text = "second"
                 }
             }
         };
         var req = new BulkInsertRequest <Blog>
         {
             Entities = new[] { blog }.ToList(),
             AllowNotNullSelfReferences = false,
             SortUsingClusteredIndex    = true,
             Recursive = true
         };
         var response = db.BulkInsertAll(req);
     }
 }