/// <summary> /// Uses linq to find the first 5 products in the NorthWind class /// </summary> /// <param name="northWind">A NorthWind class</param> public static void First5Products(NorthWind northWind) { Console.WriteLine(""); Console.WriteLine("First 5 products"); //Write list with name of first 5 products northWind.Products().Take(5).ToList().ForEach(x => WriteLineLock(x.ProductName)); }
/// <summary> /// Uses linq to find the "Counting of orders by shipping country. Output by descending count" in the NorthWind class /// </summary> /// <param name="northWind">A NorthWind class</param> public static void OrdersByShippingCountry(NorthWind northWind) { Console.WriteLine(""); Console.WriteLine("Counting of orders by shipping country. Output by descending count"); //Write the counting of orders by shipping country. Order the output by descending count [use LINQ] Dictionary<string, int> countryCount = new Dictionary<string, int>(); northWind.Orders().ToList().GroupBy(x => x.ShipCountry).Select(x => x.First()).ToList() .ForEach(x => countryCount.Add(x.ShipCountry, northWind.Orders().Select(a => a.ShipCountry).Where(c => c == x.ShipCountry).Count())); countryCount.Keys.ToList().OrderBy(x => countryCount[x]).ToList().ForEach(x => WriteLineLock(x + " : " + countryCount[x])); }
/// <summary> /// Instantiating Respiratory and NorthWind classes to use in solutions. /// And runs solutions. /// </summary> /// <param name="args"></param> static void Main(string[] args) { Console.WriteLine("Attaching NORTHWND.MDF"); using (NORTHWNDEntities1 db = new NORTHWNDEntities1()) { Console.WriteLine("Connecting NORTHWND.MDF"); db.Database.Connection.Open(); Console.WriteLine("Connected"); Respiratory respiratory = new Respiratory(db); NorthWind northWind = new NorthWind(respiratory); Console.WriteLine("Preparing database meta data"); //Dummy query northWind.Products().Take(0); Console.WriteLine("Ready"); // ReportingModule reportingModule = new ReportingModule(northWind); //IList<OrdersByTotalPriceDto> reportedOrders = reportingModule.TopOrdersByTotalPrice(5).Data; northWind.newOrderEvent += subscription; Console.WriteLine("Adding an order to Denmark."); northWind.AddOrder(DateTime.Now, "testName", "testAddress", "testCity", "testRegion", "2300", "Denmark"); //Write list with name of first 5 products First5Products(northWind); //Write the counting of orders by shipping country. Order the output by descending count [use LINQ] OrdersByShippingCountry(northWind); Console.WriteLine("Finished"); Console.ReadLine(); } }
public ReportingModule(NorthWind northWind) { this.northWind = northWind; }