using System.Collections.Generic;
public static void Main()
List<Customer> customers = new List<Customer>()
new Customer(){ID = Guid.NewGuid(), Age = 23, First = "Joe", Last = "Smith"},
new Customer(){ID = Guid.NewGuid(), Age = 34, First = "Kevin", Last = "Costner"},
new Customer(){ID = Guid.NewGuid(), Age = 23, First = "Sally", Last = "Smuthers"},
new Customer(){ID = Guid.NewGuid(), Age = 56, First = "Mary", Last = "Jane"},
new Customer(){ID = Guid.NewGuid(), Age = 48, First = "Jane", Last = "Kendall"},
new Customer(){ID = Guid.NewGuid(), Age = 34, First = "Eve", Last = "Shrimp"},
new Customer(){ID = Guid.NewGuid(), Age = 31, First = "Donna", Last = "Lynn"},
new Customer(){ID = Guid.NewGuid(), Age = 21, First = "Sarah", Last = "Spicer"},
List<Order> orders = new List<Order>()
new Order() {CustomerID = customers[0].ID, Description="Shoes", Price=150.23M, Quantity=1},
new Order() {CustomerID = customers[0].ID, Description="Phone", Price=130.25M, Quantity=1},
new Order() {CustomerID = customers[0].ID, Description="Jacket", Price=230.14M, Quantity=1},
new Order() {CustomerID = customers[1].ID, Description="Phone", Price=130.25M, Quantity=1},
new Order() {CustomerID = customers[1].ID, Description="Jacket", Price=230.14M, Quantity=1},
new Order() {CustomerID = customers[1].ID, Description="Pants", Price=70.56M, Quantity=1},
new Order() {CustomerID = customers[2].ID, Description="Jacket", Price=230.14M, Quantity=1},
new Order() {CustomerID = customers[2].ID, Description="Pants", Price=70.56M, Quantity=1},
new Order() {CustomerID = customers[2].ID, Description="Shirt", Price=49.99M, Quantity=1},
new Order() {CustomerID = customers[3].ID, Description="Pants", Price=70.56M, Quantity=1},
new Order() {CustomerID = customers[3].ID, Description="Shirt", Price=49.99M, Quantity=1},
new Order() {CustomerID = customers[3].ID, Description="Scarf", Price=23.69M, Quantity=1},
new Order() {CustomerID = customers[4].ID, Description="Shirt", Price=49.99M, Quantity=1},
new Order() {CustomerID = customers[4].ID, Description="Scarf", Price=23.69M, Quantity=1},
new Order() {CustomerID = customers[4].ID, Description="Car", Price=24200.15M, Quantity=1},
new Order() {CustomerID = customers[5].ID, Description="Scarf", Price=23.69M, Quantity=1},
new Order() {CustomerID = customers[5].ID, Description="Car", Price=24200.15M, Quantity=1},
new Order() {CustomerID = customers[5].ID, Description="Computer", Price=650.00M, Quantity=1},
new Order() {CustomerID = customers[6].ID, Description="Car", Price=24200.15M, Quantity=1},
new Order() {CustomerID = customers[6].ID, Description="Computer", Price=650.00M, Quantity=1},
new Order() {CustomerID = customers[6].ID, Description="Shoes", Price=150.23M, Quantity=1},
new Order() {CustomerID = customers[7].ID, Description="Computer", Price=650.00M, Quantity=1},
new Order() {CustomerID = customers[7].ID, Description="Jacket", Price=230.14M, Quantity=1},
new Order() {CustomerID = customers[7].ID, Description="Pants", Price=70.56M, Quantity=1},
IEnumerable<Customer> results = customers.OrderBy(n => n.Last);
Console.WriteLine("Customers and orders sorted by last name:");
foreach (Customer cust in results)
Console.WriteLine("{0} {1}", cust.First, cust.Last);
IEnumerable<Order> result = orders.Where(item => item.CustomerID == cust.ID).OrderBy(m => m.Description);
Console.WriteLine("Orders:");
foreach (Order ord in result)
Console.WriteLine("{0}, Price: {1}, Quantity: {2}", ord.Description, ord.Price, ord.Quantity);
var q1 = from c in customers
join o in orders on c.ID equals o.CustomerID
select new { c.First, c.Last, o.Description, o.Price, o.Quantity };
var r = q1.OrderBy(n => n.Last).ThenByDescending(n => n.Description);
double numord = r.Count();
Console.WriteLine("Total number of orders: {0}", numord);
var q2 = from c in customers
join o in orders on c.ID equals o.CustomerID
select new { c.Last, o.Description };
double numord2 = q2.Count();
Console.WriteLine("Number of orders $500 or under: {0}", numord2);
var q3 = from c in customers
join o in orders on c.ID equals o.CustomerID
select new { c.Last, o.Description };
double numord3 = q3.Count();
Console.WriteLine("Number of orders over $500: {0}", numord3);
decimal numord4 = r.Sum(p => p.Price);
Console.WriteLine("Total cost for all orders: {0}", numord4);
var q4 = from c in customers
join o in orders on c.ID equals o.CustomerID
select new { c.Last, o.Price };
decimal numord5 = q4.Sum(p => p.Price);
Console.WriteLine("Total cost for all orders for people 30 or under: {0}", numord5);
var q5 = from c in customers
join o in orders on c.ID equals o.CustomerID
select new { c.Last, o.Price };
decimal numord6 = q5.Sum(p => p.Price);
Console.WriteLine("Total cost for all orders for people over 30: {0}", numord6);
var ord2 = (from o in orders
select new { o.Description, o.Price }).Distinct().Take(3);
Console.WriteLine("The 3 least expensive products:");
Console.WriteLine("{0} {1}", ord.Description,ord.Price);
var ord3 = (from o in orders
orderby o.Price descending
select new { o.Description, o.Price }).Distinct().Take(3);
Console.WriteLine("The 3 most expensive products:");
foreach (var ord in ord3)
Console.WriteLine("{0} {1}", ord.Description,ord.Price);
public Guid ID { get; set; }
public int Age { get; set; }
public string First { get; set; }
public string Last { get; set; }
public Guid CustomerID { get; set; }
public string Description { get; set; }
public decimal Price { get; set; }
public int Quantity { get; set; }