Beispiel #1
0
        public static void Seed(BookShopSysDbContext context)
        {
            Book[] books = BookGenerator.CreateBooks();

            context.Books.AddRange(books);

            context.SaveChanges();

            Console.WriteLine("Sample data inserted successfully.");
        }
        public static int RemoveBooks(BookShopSysDbContext db)
        {
            var books = db.Books
                        .Where(b => b.Copies < 4200);
            int result = books.Count();

            db.Books.RemoveRange(books);
            db.SaveChanges();

            return(result);
        }
        public static void IncreasePrices(BookShopSysDbContext db)
        {
            var books = db.Books
                        .Where(b => b.ReleaseDate.Value.Year < 2010);

            foreach (var b in books)
            {
                b.Price += 5m;
            }

            db.SaveChanges();
        }