Example #1
0
        public static void EnsurePopulated(IApplicationBuilder application)
        {
            BookstoreContext context = application.ApplicationServices.
                                       CreateScope().ServiceProvider.GetRequiredService <BookstoreContext>();

            if (context.Database.GetPendingMigrations().Any())
            {
                context.Database.Migrate();
            }

            if (!context.Books.Any())
            {
                context.Books.AddRange(

                    new Book
                {
                    Title     = "Les Miserables",
                    FirstName = "Victor",
                    LastName  = "Hugo",
                    Publisher = "Signet",
                    ISBN      = "978-0451419439",
                    Class     = "Fiction",
                    Category  = "Classic",
                    Price     = 9.95
                },

                    new Book
                {
                    Title     = "Team of Rivals",
                    FirstName = "Doris Kearns",
                    LastName  = "Goodwin",
                    Publisher = "Simon & Schuster",
                    ISBN      = "978-0743270755",
                    Class     = "Non-Fiction",
                    Category  = "Biography",
                    Price     = 14.58
                },

                    new Book
                {
                    Title     = "The Snowball",
                    FirstName = "Alice",
                    LastName  = "Schroeder",
                    Publisher = "Bantam",
                    ISBN      = "978-0553384611",
                    Class     = "Non-Fiction",
                    Category  = "Biography",
                    Price     = 21.54
                },

                    new Book
                {
                    Title     = "American Ulysses",
                    FirstName = "Ronald C.",
                    LastName  = "White",
                    Publisher = "Random House",
                    ISBN      = "978-0812981254",
                    Class     = "Non-Fiction",
                    Category  = "Biography",
                    Price     = 11.61
                },

                    new Book
                {
                    Title     = "Unbroken",
                    FirstName = "Laura",
                    LastName  = "Hillenbrand",
                    Publisher = "Random House",
                    ISBN      = "978-0812974492",
                    Class     = "Non-Fiction",
                    Category  = "Historical",
                    Price     = 13.33
                },

                    new Book
                {
                    Title     = "The Great Train Robbery",
                    FirstName = "Michael",
                    LastName  = "Crichton",
                    Publisher = "Vintage",
                    ISBN      = "978-0804171281",
                    Class     = "Fiction",
                    Category  = "Historical Fiction",
                    Price     = 15.95
                },

                    new Book
                {
                    Title     = "Deep Work",
                    FirstName = "Cal",
                    LastName  = "Newport",
                    Publisher = "Grand Central Publishing",
                    ISBN      = "978-1455586691",
                    Class     = "Non-Fiction",
                    Category  = "Self-Help",
                    Price     = 14.99
                },

                    new Book
                {
                    Title     = "It's Your Ship",
                    FirstName = "Michael",
                    LastName  = "Abrashoff",
                    Publisher = "Grand Central Publishing",
                    ISBN      = "978-1455523023",
                    Class     = "Non-Fiction",
                    Category  = "Self-Help",
                    Price     = 21.66
                },

                    new Book
                {
                    Title     = "The Virgin Way",
                    FirstName = "Richard",
                    LastName  = "Branson",
                    Publisher = "Portfolio",
                    ISBN      = "978-1591847984",
                    Class     = "Non-Fiction",
                    Category  = "Business",
                    Price     = 29.16
                },

                    new Book
                {
                    Title     = "Sycamore Row",
                    FirstName = "John",
                    LastName  = "Grisham",
                    Publisher = "Bantam",
                    ISBN      = "978-0553393613",
                    Class     = "Fiction",
                    Category  = "Thrillers",
                    Price     = 15.03
                });

                context.SaveChanges();
            }
        }