static void Main(string[] args)
        {
            var context = new GeographyEntities();

            foreach (var continent in context.Continents)
            {
                Console.WriteLine(continent.ContinentName);
            }
        }
예제 #2
0
        static void Main(string[] args)
        {
            var context = new GeographyEntities();

            foreach (var continent in context.Continents)
            {
                Console.WriteLine(continent.ContinentName);
            }
        }
        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));  //Test

                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();
            }
        }
예제 #4
0
        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);
        }
        static void Main()
        {
            var context = new GeographyEntities();

            var countryMon = 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();

            //foreach (var item in countryMon)
            //{
            //    Console.WriteLine(item.CountryName + "; " + string.Join(", ", item.Monasteries));
            //}

            XElement xmlMonasteries = new XElement("monasteries");

            foreach (var country in countryMon)
            {
                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");
        }