Exemple #1
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);
            }
        }