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

            var countryMonasteries = context.Countries
                 .OrderBy(c => c.CountryName)
                 .Where(c => c.Monasteries.Any())
                 .Select(c => new
                 {
                     c.CountryName,
                     Monasteries = c.Monasteries
                                    .OrderBy(m => m.Name)
                                    .Select(m => m.Name)
                 }).ToList();

            XElement xmlMonasteries = new XElement("monasteries");
            foreach (var country in countryMonasteries)
            {
                var xmlCountry = new XElement("country");
                xmlCountry.Add(new XAttribute("name", country.CountryName));

                foreach (var monastrery in country.Monasteries)
                {
                    xmlCountry.Add(new XElement("monastery", monastrery));
                }

                xmlMonasteries.Add(xmlCountry);
            }

            var xmlDoc = new XDocument(xmlMonasteries);
            xmlDoc.Save("../../countryMon.xml");
        }
        static void Main()
        {
            var context = new GeographyEntities();

            var continents = context.Continents.Select(c => c.ContinentName);

            foreach (var continent in continents)
            {
                Console.WriteLine(continent);
            }
        }
        static void Main()
        {
            var context = new GeographyEntities();

            var continents = context.Continents.Select(c => c.ContinentName);

            foreach (var continent in continents)
            {
                Console.WriteLine(continent);
            }
        }
        static void Main()
        {
            var context = new GeographyEntities();

            XDocument xmlDoc = XDocument.Load("../../rivers.xml");

            var riverNodes = xmlDoc.XPathSelectElements("/rivers/river");

            foreach (var riverNode in riverNodes)
            {
                string riverName = riverNode.Element("name").Value;
                int riverLength = int.Parse(riverNode.Element("length").Value);
                string riverOutflow = riverNode.Element("outflow").Value;

                int? riverDrainageArea = null;
                if (riverNode.Element("drainage-area") != null)
                {
                    riverDrainageArea = int.Parse(riverNode.Element("drainage-area").Value);
                }

                int? riverAverageDischarge = null;
                if (riverNode.Element("average-discharge") != null)
                {
                    riverAverageDischarge = int.Parse(riverNode.Element("average-discharge").Value);
                }

                //Console.WriteLine("{0} {1} {2} {3} {4}", riverName, riverLength, riverOutflow, riverDrainageArea, riverAverageDischarge);

                var countryNodes = riverNode.XPathSelectElements("countries/country");
                var countries = countryNodes.Select(c => c.Value);
                //Console.WriteLine("{0}->{1}", riverName, string.Join(", ", countries));

                var river = new River()
                {
                    RiverName = riverName,
                    Length = riverLength,
                    Outflow = riverOutflow,
                    DrainageArea = riverDrainageArea,
                    AverageDischarge = riverAverageDischarge
                };

                context.Rivers.Add(river);

                var countryNames = countryNodes.Select(c => c.Value);

                foreach (var countryName in countryNames)
                {
                    var countryToAddToRiver = context.Countries.FirstOrDefault(c => c.CountryName == countryName);
                    river.Countries.Add(countryToAddToRiver);
                }

                context.SaveChanges();
            }
        }
        static void Main()
        {
            var context = new GeographyEntities();

            var rivers = context.Rivers
                .OrderByDescending(r => r.Length)
                .Select(r => new
                {
                    r.RiverName,
                    r.Length,
                    Countries = r.Countries
                                 .OrderBy(c => c.CountryName)
                                 .Select(c => c.CountryName)
                }).ToList();

            var JSerializer = new JavaScriptSerializer();
            var jsonRivers = JSerializer.Serialize(rivers);
            File.WriteAllText("../../rivers.json", jsonRivers);
        }