コード例 #1
0
 private static void AddNewCountry(CountriesEntities countriesEntities)
 {
     Country country = new Country();
     country.CountryName = "Greece";
     country.Population = 500000;
     country.Cities.Add(new City{ CityName = "Athens" });
     country.Cities.Add(new City{ CityName = "Alexandroupoli" });
     country.Cities.Add(new City{ CityName = "Sparta" });
     countriesEntities.Countries.AddObject(country);
     countriesEntities.SaveChanges();
 }
コード例 #2
0
 private static void PrintCountriesWithoutQueryProblem(CountriesEntities countriesEntities)
 {
     string separatorLine = new string('-', 30);
     foreach (var country in countriesEntities.Countries.Include("Cities"))
     {
         // Console.WriteLine(country.CountryName + "\nCities:");
         foreach (var city in country.Cities)
         {
             //        Console.WriteLine("      {0}", city.CityName);
         }
         // Console.WriteLine(SeparatorLine);
     }
 }
コード例 #3
0
        private static void PrintCountriesAndCitiesWithQueryProblem(CountriesEntities countriesEntities)
        {
            string separatorLine = new string('-', 30);

            foreach (var country in countriesEntities.Countries)
            {
                // Console.WriteLine(country.CountryName + "\nCities:");
                foreach (var city in country.Cities)
                {
                    //          Console.WriteLine("      {0}", city.CityName);
                }
                // Console.WriteLine(SeparatorLine);
            }
        }
コード例 #4
0
        private static void AddNewCountry(CountriesEntities countriesEntities)
        {
            Country country = new Country();

            country.CountryName = "Greece";
            country.Population  = 500000;
            country.Cities.Add(new City {
                CityName = "Athens"
            });
            country.Cities.Add(new City {
                CityName = "Alexandroupoli"
            });
            country.Cities.Add(new City {
                CityName = "Sparta"
            });
            countriesEntities.Countries.AddObject(country);
            countriesEntities.SaveChanges();
        }
コード例 #5
0
        static void Main()
        {
            using (CountriesEntities countriesEntities = new CountriesEntities())
            {
                DateTime start = DateTime.Now;

                PrintCountriesAndCitiesWithQueryProblem(countriesEntities);
                Console.WriteLine(DateTime.Now - start);
                start = DateTime.Now;
                PrintCountriesWithoutQueryProblem(countriesEntities);
                Console.WriteLine(DateTime.Now - start);

                //AddNewCountry(countriesEntities);
                //foreach (var country in countriesEntities.Countries)
                //{
                //    AddCities(country);
                //}
                //countriesEntities.SaveChanges();
            }
        }
コード例 #6
0
        static void Main()
        {
            using (CountriesEntities countriesEntities = new CountriesEntities())
            {
                DateTime start = DateTime.Now;

                PrintCountriesAndCitiesWithQueryProblem(countriesEntities);
                Console.WriteLine(DateTime.Now - start);
                start = DateTime.Now;
                PrintCountriesWithoutQueryProblem(countriesEntities);
                Console.WriteLine(DateTime.Now - start);

                //AddNewCountry(countriesEntities);
                //foreach (var country in countriesEntities.Countries)
                //{
                //    AddCities(country);
                //}
                //countriesEntities.SaveChanges();
            }
        }