예제 #1
0
 private static void InitializeData(BooksContext context)
 {
     context.Database.Migrate();
     Seed(context);
 }
예제 #2
0
        private static void AddBooks(BooksContext context)
        {
            var pa = context.Publishers.Single(r => r.Name == "Anchor");
            var pp = context.Publishers.Single(r => r.Name == "Prentice Hall");
            var ps = context.Publishers.Single(r => r.Name == "Scholastic");

            var db = context.Authors.Single(r => r.Name == "Dan Brown");
            var rm = context.Authors.Single(r => r.Name == "Robert C. Martin");
            var jr = context.Authors.Single(r => r.Name == "J.K. Rowling");
            var jk = context.Authors.Single(r => r.Name == "Jon Krakauer");

            books = new List <Book>
            {
                new Book
                {
                    Name      = "Into Thin Air",
                    Publisher = pa,
                    Author    = jk
                },
                new Book
                {
                    Name      = "Into the Wild",
                    Publisher = pa,
                    Author    = jk
                },
                new Book
                {
                    Name      = "Under the Banner of Heaven: A Story of Violent Faith",
                    Publisher = pa,
                    Author    = jk
                },
                new Book
                {
                    Name      = "The Lost Symbol",
                    Publisher = pa,
                    Author    = db
                },
                new Book
                {
                    Name      = "Inferno",
                    Publisher = pa,
                    Author    = db
                },
                new Book
                {
                    Name      = "The Da Vinci Code",
                    Publisher = pa,
                    Author    = db
                },
                new Book
                {
                    Name      = "The Clean Coder: A Code of Conduct for Professional Programmers",
                    Publisher = pp,
                    Author    = rm
                },
                new Book
                {
                    Name      = "Clean Code: A Handbook of Agile Software Craftsmanship",
                    Publisher = pp,
                    Author    = rm
                },
                new Book
                {
                    Name      = "Clean Architecture: A Craftsman's Guide to Software Structure and Design",
                    Publisher = pp,
                    Author    = rm
                },
                new Book
                {
                    Name      = "Harry Potter and the Sorcerer's Stone",
                    Publisher = ps,
                    Author    = jr
                },
                new Book
                {
                    Name      = "Harry Potter And The Chamber Of Secrets",
                    Publisher = ps,
                    Author    = jr
                },
                new Book
                {
                    Name      = "Harry Potter and the Prisoner of Azkaban",
                    Publisher = ps,
                    Author    = jr
                },
                new Book
                {
                    Name      = "Harry Potter And The Goblet Of Fire",
                    Publisher = ps,
                    Author    = jr
                }
            };

            if (!context.Books.Any())
            {
                context.Books.AddRange(books);
                context.SaveChanges();
            }
        }
예제 #3
0
 public static void Seed(BooksContext context)
 {
     AddPublishers(context);
     AddAuthors(context);
     AddBooks(context);
 }