コード例 #1
0
 public static void SeedData(ColorContext context)
 {
     System.Console.WriteLine("Application Migration");
     context.Database.Migrate();
     if (!context.ColorItems.Any())
     {
         System.Console.WriteLine("Adding data");
         context.ColorItems.AddRange(
             new Color()
         {
             ColorName = "red",
         }, new Color()
         {
             ColorName = "orange",
         }, new Color()
         {
             ColorName = "black",
         }, new Color()
         {
             ColorName = "yellow",
         }
             );
         context.SaveChanges();
     }
     else
     {
         System.Console.WriteLine("Already have data.");
     }
 }
コード例 #2
0
ファイル: PrepDB.cs プロジェクト: bpbeernie/ColorApi
        public static void SeedData(ColorContext context)
        {
            System.Console.WriteLine("Applying Migrations...");

            context.Database.Migrate();
            if (!context.ColorItems.Any())
            {
                Console.WriteLine("Adding data = seeding...");
                context.ColorItems.AddRange(
                    new Color()
                {
                    ColorName = "Red"
                },
                    new Color()
                {
                    ColorName = "Orange"
                },
                    new Color()
                {
                    ColorName = "Red"
                },
                    new Color()
                {
                    ColorName = "Yellow"
                },
                    new Color()
                {
                    ColorName = "Green"
                },
                    new Color()
                {
                    ColorName = "Blue"
                }
                    );

                context.SaveChanges();
            }
            else
            {
                Console.WriteLine("Already have data");
            }
        }