예제 #1
0
        public static void Initialize(CrudContext context)
        {
            context.Database.EnsureCreated();

            if (context.People.Any())
            {
                return;
            }

            var people = new Person[]
            {
                new Person {
                    FirstName = "John", LastName = "Johnson", Email = "*****@*****.**", Age = 32, Subscribed = true
                },
                new Person {
                    FirstName = "Bob", LastName = "Bobson", Email = "*****@*****.**", Age = 35, Subscribed = true
                },
                new Person {
                    FirstName = "Sally", LastName = "Stevens", Email = "*****@*****.**", Age = 24, Subscribed = false
                },
            };

            foreach (Person p in people)
            {
                context.People.Add(p);
            }
            context.SaveChanges();
        }
예제 #2
0
        public static void Initialize(CrudContext context)
        {
            // Creates the database if it doesnt exist
            context.Database.EnsureCreated();

            if (context.UsedInv.Any())
            {
                return;
            }

            // if it doesnt exist populate it
            var inventory = new AddUsedInventory[]
            {
                new AddUsedInventory {
                    Year = 2015, Make = "Ford", Model = "F-150", Trim = "Lariat", VIN = 12345678901234543
                },
                new AddUsedInventory {
                    Year = 2012, Make = "Toyota", Model = "Camry", Trim = "LS", VIN = 12345678901234543
                },
                new AddUsedInventory {
                    Year = 2012, Make = "BMW", Model = "i3", Trim = "3 Series", VIN = 12345678901234543
                },
                new AddUsedInventory {
                    Year = 2011, Make = "Volkswagen", Model = "Pasat", Trim = "P", VIN = 12345678901234543
                }
            };

            foreach (AddUsedInventory i in inventory)
            {
                context.UsedInv.Add(i);
            }
            context.SaveChanges();
        }