示例#1
0
        private static void RemoveBooksWithFewCopies(ShopSystemContext context)
        {
            var booksToRemove = context.Books.Where(b => b.Copies < 4200);
            var count         = booksToRemove.Count();

            context.Books
            .RemoveRange(booksToRemove);

            context.SaveChanges();

            Console.WriteLine($"{count} books were deleted");
        }
示例#2
0
        private static void IncreaseBooksCopies(ShopSystemContext context)
        {
            var books = context.Books
                        .ToList();

            int count = 0;

            foreach (var book in books)
            {
                if (book.ReleaseDate > DateTime.Parse("06/01/2013"))
                {
                    book.Copies += 44;
                    count       += 44;
                }
            }

            context.SaveChanges();

            Console.WriteLine(count);
        }