コード例 #1
0
ファイル: SeedDataGames.cs プロジェクト: Code-Provider/.NET
 public static void Initialize(IServiceProvider serviceProvider)
 {
     using (var context = new MiniProjetContext(
                serviceProvider.GetRequiredService <
                    DbContextOptions <MiniProjetContext> >()))
     {
         if (context.VideoGame.Any())
         {
             return;
         }
         context.VideoGame.AddRange(
             new VideoGame
         {
             Title       = "Resident Evil 2",
             genre       = "Survival Horror",
             Developer   = "Capcom",
             Plateform   = "PlayStation",
             ReleaseDate = DateTime.Parse("2019-1-25"),
             Rating      = 9
         },
             new VideoGame
         {
             Title       = "Watch Dogs",
             genre       = "Action",
             Developer   = "Ubisoft",
             Plateform   = "Xbox",
             ReleaseDate = DateTime.Parse("2014-3-05"),
             Rating      = 8
         },
             new VideoGame
         {
             Title       = "the elder scrolls v skyrim",
             genre       = "RPG",
             Developer   = " Bethesda",
             Plateform   = "PC",
             ReleaseDate = DateTime.Parse("2011-11-11"),
             Rating      = 10
         },
             new VideoGame
         {
             Title       = "Devil May Cry 5",
             genre       = "Action",
             Developer   = " Capcom",
             Plateform   = "PlayStation",
             ReleaseDate = DateTime.Parse("2019-3-08"),
             Rating      = 10
         }
             );
         context.SaveChanges();
     }
 }
コード例 #2
0
 public static void Initialize(IServiceProvider serviceProvider)
 {
     using (var context = new MiniProjetContext(
                serviceProvider.GetRequiredService <
                    DbContextOptions <MiniProjetContext> >()))
     {
         if (context.Book.Any())
         {
             return;
         }
         context.Book.AddRange(
             new Book
         {
             Title       = "Harry Potter",
             author      = "J.K Rowling",
             Category    = "Roman",
             ReleaseDate = DateTime.Parse("1997-6-26"),
             Rating      = 10
         },
             new Book
         {
             Title       = "Candide",
             author      = "Voltaire",
             Category    = "Conte philosophique",
             ReleaseDate = DateTime.Parse("1759-2-26"),
             Rating      = 9
         },
             new Book
         {
             Title       = "Le Dernier jour d'un condamné",
             author      = "Victor Hugo",
             Category    = "Roman",
             ReleaseDate = DateTime.Parse("1829-2-26"),
             Rating      = 10
         },
             new Book
         {
             Title       = "Au coeur des ténebres",
             author      = "Joseph Conrad",
             Category    = "Nouvelle",
             ReleaseDate = DateTime.Parse("1902-2-05"),
             Rating      = 8
         }
             );
         context.SaveChanges();
     }
 }