static void GetOrderedCars() { var query = from c in Gibdd.GetCars() orderby c.Body select new { Name = c.Name, Body = c.Body }; foreach (var q in query) { Console.WriteLine("{0} {1}", q.Name, q.Body); } }
static void CalcAvgFineByDriver() { var query = from f in Gibdd.GetFines() group f by f.DriverId into g select new { Did = g.Key, AvgFines = g.Average(k => k.Cost) }; foreach (var q in query) { Console.WriteLine("{0} {1}", q.Did, q.AvgFines); } }
static void GetUnpaidFines() { var fines = from p in Gibdd.GetFines() where p.IsPaid == true select p; foreach (var f in fines) { Console.WriteLine("{0} {1} {2}", f.DriverId, f.Cause, f.Cost); } }
static void GetCarsByBody(string name) { var query = from c in Gibdd.GetCars() let carBody = c.Body.ToLower() where carBody == name.ToLower() select c.Name; foreach (var q in query) { Console.WriteLine("{0}", q); } }
static void GetFinesForExperience(int exp) { IList <Fines> fines = Gibdd.GetFines(); IList <Drivers> drivers = Gibdd.GetDrivers(); var query = from f in fines join d in drivers on f.DriverId equals d.Id where d.Experience > exp select new { FId = f.Id, DId = d.Id, Cause = f.Cause }; foreach (var q in query) { Console.WriteLine("{0} {1} {2}", q.FId, q.DId, q.Cause); } Console.WriteLine("End"); Console.Read(); }