Ejemplo n.º 1
0
        public void Test_PartialColumnUpdate()
        {
            var dbContext = new SouthSeaDbContext();
            var book      = dbContext.Books.Find(1);

            var originalName = book.Name;
            var targetName   = "newName";

            book.Name   = targetName;
            book.Author = "yozian";

            dbContext.Update(
                book,
                x => x.Name
                );

            dbContext.SaveChanges();

            var updatedBook = dbContext
                              .Books
                              .Where(x => x.Id == 1)
                              .AsNoTracking()
                              .First();


            Assert.AreEqual(targetName, updatedBook.Name);
            Assert.AreEqual(book.Author, updatedBook.Author);
        }
Ejemplo n.º 2
0
        public void Setup()
        {
            var dbContext = new SouthSeaDbContext();

            var books = Enumerable.Range(1, 10)
                        .Select(x => new Book()
            {
                Name   = x.ToString(),
                Author = x.ToString("d3")
            });


            dbContext.AddRange(books);

            dbContext.SaveChanges();
        }