public static void EnsureSeedDataForContext(this CityInfoContext context)
        {
            if (context.Cities.Any())
            {
                return;
            }

            var cities = new List <City>
            {
                new City
                {
                    Name             = "New York",
                    Description      = "City Description 1",
                    PointsOfInterest = new List <PointOfInterest>
                    {
                        new PointOfInterest {
                            Name = "Central Park", Description = "Description 1"
                        },
                        new PointOfInterest {
                            Name = "Empire State", Description = "Description 2"
                        }
                    }
                },
                new City
                {
                    Name             = "Lima",
                    Description      = "City Description 2",
                    PointsOfInterest = new List <PointOfInterest>
                    {
                        new PointOfInterest {
                            Name = "Convento", Description = "Description 3"
                        },
                        new PointOfInterest {
                            Name = "Parque", Description = "Description 4"
                        }
                    }
                },
                new City
                {
                    Name             = "Rio",
                    Description      = "City Description 3",
                    PointsOfInterest = new List <PointOfInterest>
                    {
                        new PointOfInterest {
                            Name = "Favelas", Description = "Description 4"
                        },
                        new PointOfInterest {
                            Name = "Estadio", Description = "Description 5"
                        }
                    }
                }
            };

            context.AddRange(cities);
            context.SaveChanges();
        }
Esempio n. 2
0
        public static void EnsureSeedDataForContext(this CityInfoContext context)
        {
            if (context.Cities.Any())
            {
                return;
            }

            var cities = new List <City>
            {
                new City
                {
                    Name             = "New York City",
                    Description      = "The one with the big park.",
                    PointsOfInterest = new List <PointOfInterest>
                    {
                        new PointOfInterest
                        {
                            Name        = "Central Park",
                            Description = "The most visited urban park in the US."
                        },
                        new PointOfInterest
                        {
                            Name        = "Empire State Building",
                            Description = "A 102-story skyscrapper located in Midtown Manhattan."
                        }
                    }
                },
                new City
                {
                    Name             = "Antwerp",
                    Description      = "The one with the cathedral that was never finished.",
                    PointsOfInterest = new List <PointOfInterest>
                    {
                        new PointOfInterest
                        {
                            Name        = "Cathedral of Our Lady",
                            Description = "A gothic style cathedral"
                        },
                        new PointOfInterest
                        {
                            Name        = "Antwerp Central Station",
                            Description = "First train in Belgium"
                        }
                    }
                },
                new City
                {
                    Name             = "Paris",
                    Description      = "The one with that big tower.",
                    PointsOfInterest = new List <PointOfInterest>
                    {
                        new PointOfInterest
                        {
                            Name        = "Eiffel Tower",
                            Description = "Iron lattice tower"
                        },
                        new PointOfInterest
                        {
                            Name        = "The Louvre",
                            Description = "The world's largest museum."
                        }
                    }
                }
            };

            context.AddRange(cities);
            context.SaveChanges();
        }