static void Main(string[] args)
        {
            var db = new GeographyEntities();
            var countries = db.Countries
            .OrderBy(c => c.CountryName)
            .Select(c => new
            {
                coutryName = c.CountryName,
                monasteries = c.Monasteries.OrderBy(m => m.Name).Select(m => m.Name)
            }).ToList();

            XElement root = new XElement("monasteries");
            foreach (var country in countries)
            {
                if (country.monasteries.Count() != 0)
                {
                    var xmlCountry = new XElement("country");
                    xmlCountry.Add(new XAttribute("name", country.coutryName));
                    foreach (var xmlMonasteries in country.monasteries)
                    {
                        xmlCountry.Add(new XElement("monastery", xmlMonasteries));
                    }
                    root.Add(xmlCountry);   
                }
            }

            var xmlDoc = new XDocument(root);
            xmlDoc.Save("../../monasteries.xml");
        }
 static void Main()
 {
     var db = new GeographyEntities();
     var continentNames = db.Continents.Select(c => c.ContinentName).ToList();
     foreach (var continentName in continentNames)
     {
         Console.WriteLine(continentName);
     }
 }
        static void Main()
        {
            var db = new GeographyEntities();
            var rivers = db.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)
            }).ToList();

            var json = new JavaScriptSerializer().Serialize(rivers);
            File.WriteAllText("../../rivers.json", json);
        }
        static void Main()
        {
            var db = new GeographyEntities();

            var xmlDoc = XDocument.Load("../../rivers.xml");
            var elements = xmlDoc.XPathSelectElements("rivers/river");
            foreach (var element in elements)
            {
                string riverName = element.Element("name").Value;
                int length = Convert.ToInt32(element.Element("length").Value);
                string outflow = element.Element("outflow").Value;
                
                int? drainAgeArea = null;
                if (element.Element("drainage-area") != null)
                {
                    drainAgeArea = Convert.ToInt32(element.Element("drainage-area").Value);
                }

                int? averageDischarge = null;
                if (element.Element("average-discharge") != null)
                {
                    drainAgeArea = Convert.ToInt32(element.Element("average-discharge").Value);
                }

                Console.WriteLine("{0} - {1} - {2} - {3} - {4}", riverName, length, outflow, drainAgeArea, averageDischarge);
                
                var river = new River()
                {
                    RiverName = riverName,
                    Length = length,
                    Outflow = outflow,
                    AverageDischarge = averageDischarge,
                    DrainageArea = drainAgeArea
                };

                db.Rivers.Add(river);

                var countryNodes = element.XPathSelectElements("countries/country");
                var countryRiverNames = countryNodes.Select(c => c.Value);
                foreach (var countryName in countryRiverNames)
                {
                    var country = db.Countries.FirstOrDefault(c => c.CountryName == countryName);
                    river.Countries.Add(country);
                }

                db.SaveChanges();
            }
        }