private static void Main()
        {
            var context = new GeographyEntities();

            var xmlDoc = XDocument.Load("../../rivers.xml");
            var riverElements = xmlDoc.Root.Elements();
            foreach (var riverElement in riverElements)
            {
                var riverEntity = new River();
                riverEntity.RiverName = riverElement.Element("name").Value;
                riverEntity.Length = int.Parse(riverElement.Element("length").Value);
                riverEntity.Outflow = riverElement.Element("outflow").Value;
                if (riverElement.Element("drainage-area") !=null)
                {
                    riverEntity.DrainageArea = int.Parse( riverElement.Element("drainage-area").Value);
                }
                if (riverElement.Element("average-discharge") != null)
                {
                    riverEntity.AverageDischarge = int.Parse(riverElement.Element("average-discharge").Value);
                }

               ParseAndAddCountriesToRiver(riverElement, context, riverEntity);

                context.Rivers.Add(riverEntity);
            }

            context.SaveChanges();
        }
 static void Main(string[] args)
 {
     var context = new GeographyEntities();
     var continets = context.Continents
         .Select(c=> c.ContinentName);
     foreach (var continent in continets)
     {
         Console.WriteLine("{0}", continent);
     }
 }
        private static void Main()
        {
            var context = new GeographyEntities();
            var rivers = context.Rivers
                .OrderByDescending(r => r.Length)
                .Select(r => new
                {
                    riverName = r.RiverName,
                    riverLength = r.Length,
                    countries = r.Countries
                        .OrderBy(c => c.CountryName)
                        .Select(c => c.CountryName)

                });
            var jsSerializer = new JavaScriptSerializer();
            var riversJason = jsSerializer.Serialize(rivers.ToList());
            File.WriteAllText(@"rivers.json", riversJason);
        }
 private static void ParseAndAddCountriesToRiver(
  XElement riverElement, GeographyEntities context, River riverEntity)
 {
     var countryElements = riverElement.XPathSelectElements("countries/country");
     foreach (var countryElement in countryElements)
     {
         var countryName = countryElement.Value;
         var countryEntity = context.Countries.FirstOrDefault(c => c.CountryName == countryName);
         if (countryEntity != null)
         {
             riverEntity.Countries.Add(countryEntity);
         }
         else
         {
             throw new Exception(string.Format("Cannot find country {0} in the DB", countryName));
         }
     }
 }
        static void Main()
        {
            var context = new GeographyEntities();

            var countries = context.Countries
                .Where(c=> c.Monasteries.Count>0)
                .OrderBy(c=> c.CountryName)
                .Select(c => new
                {
                    country = c.CountryName,
                    monastaries = c.Monasteries
                        .OrderBy(m=>m.Name)
                        .Select(m => m.Name)
                });
            //foreach (var country in countries)
            //{
            //    Console.WriteLine(country.country + ' ' + string.Join(", ",country.monastaries)
            //        );
            //}

            var xmlDoc = new XDocument();
            //1. Root
            var rootXml = new XElement("monasteries");
            xmlDoc.Add(rootXml);

            foreach (var country in countries)
            {
                var countryXml = new XElement("country", new XAttribute("name", country.country) );
             rootXml.Add(countryXml);
                foreach (var monastery in country.monastaries)
                {
                    var monasteryXml = new XElement("monastery", monastery);
                    countryXml.Add(monasteryXml);
                }
            }
            xmlDoc.Save("monasteries.xml");
        }