Beispiel #1
0
        public static void Do()
        {
            var countries = CountryRecord.Retrieve();

            using (var context = new ClimateContext())
            {
                context.Countries.RemoveRange(context.Countries.ToList());
                foreach (var country in countries.OrderByDescending(x => x.population))
                {
                    var dbCountry = new Domain.Country
                    {
                        Name       = country.name,
                        Population = country.population
                    };
                    context.Countries.Add(dbCountry);

                    var capital = new Domain.City
                    {
                        IsCapital = true,
                        Country   = dbCountry,
                        Name      = country.capital
                    };
                    context.Cities.Add(capital);
                    Console.WriteLine("{0} - done", country.name);
                }
                context.SaveChanges();
            }
        }
Beispiel #2
0
        public static void Do()
        {
            var countries = CountryRecord.Retrieve();

            using (var context = new ClimateContext())
            {
                var dbCountries = context.Countries.Include(x => x.Cities).ToList();
                var joined      = countries.Join(dbCountries, x => x.name, x => x.Name, (dto, db) => new { dto, db });
                foreach (var pair in joined)
                {
                    if (pair.dto.latlng != null && pair.dto.latlng.Length == 2)
                    {
                        foreach (var city in pair.db.Cities)
                        {
                            city.Lat = pair.dto.latlng[0];
                            city.Lon = pair.dto.latlng[1];
                        }
                    }
                }
                context.SaveChanges();
            }
        }