private static void RemoveBooks(BookSystemDbContext context)
        {
            var booksForDelete = context.Books.Where(b => b.Copies < 4200).ToList();

            int totalNumberOfBooksDeleted = context.Books.Where(b => b.Copies < 4200).Delete();

            context.SaveChanges();

            Console.WriteLine($"{totalNumberOfBooksDeleted} books were deleted");
        }
Exemplo n.º 2
0
        private static void SetupBooksRelatedBooks(BookSystemDbContext context)
        {
            var books = context.Books.Take(3).ToList();

            books[0].RelatedBooks.Add(books[1]);
            books[1].RelatedBooks.Add(books[1]);
            books[0].RelatedBooks.Add(books[1]);
            books[2].RelatedBooks.Add(books[1]);

            context.SaveChanges();
        }
        private static void IncreaseBookCopies(BookSystemDbContext context)
        {
            int totalBooksUpdated = context.Books
                                    .Where(b => b.ReleaseDate > new DateTime(2013, 06, 06))
                                    .Update(b => new Book {
                Copies = b.Copies + 44
            });

            context.SaveChanges();

            int totalCopiesAdded = 44 * totalBooksUpdated;

            Console.WriteLine(totalCopiesAdded);
        }