/// <summary> /// 点标记 /// </summary> public void Show() { var list = new ProductList(); var customers = list.GetCustomerList(); Console.WriteLine(); Console.WriteLine("GroupBy_Nested 点标记"); //n % 5 //var result = products.GroupBy(g => g.Category).Select(g => new { Category = g.Key, products = g }); //Print(result); }
/// <summary> /// 点标记 /// </summary> public void Show() { var list = new ProductList(); var customers = list.GetCustomerList(); Console.WriteLine(); Console.WriteLine("Skip_Nested 点标记"); //First 3 numbers: //var result = customers.Where(c=>c.Region=="WA").J //Print(result); }
/// <summary> /// 点标记 /// </summary> public void Show() { var productList = new ProductList(); var customers = productList.GetCustomerList(); Console.WriteLine(); Console.WriteLine("Where_Drilldown 点标记"); //Customers from Washington and their orders: var result = customers.Where(t => t.Region == "WA"); Print(result); }
public void Show() { var list = new ProductList(); var customers = list.GetCustomerList(); var orderCounts = from c in customers select new { c.CustomerID, OrderCount = c.Orders.Count() }; foreach (var item in orderCounts) { Console.WriteLine(item); } }
/// <summary> /// 查询表达式 /// </summary> /// <param name="x"></param> public void Show(int x) { var productList = new ProductList(); var customers = productList.GetCustomerList(); Console.WriteLine(); Console.WriteLine("Where_Drilldown 查询表达式"); //Customers from Washington and their orders: var result = from t in customers where t.Region == "WA" select t; Print(result); }
/// <summary> /// 查询表达式 /// </summary> /// <param name="x"></param> public void Show(int x) { var list = new ProductList(); var customers = list.GetCustomerList(); Console.WriteLine(); Console.WriteLine("Skip_Nested 查询表达式"); //First 3 numbers: var result = (from a in customers from b in a.Orders where a.Region == "WA" select new { a.CustomerID, b.OrderID, b.OrderDate }).Skip(3); Print(result); }
/// <summary> /// 查询表达式 /// </summary> /// <param name="x"></param> public void Show(int x) { var list = new ProductList(); var customers = list.GetCustomerList(); Console.WriteLine(); Console.WriteLine("SelectMany_Compound_from_3 查询表达式"); //o.OrderDate >= new DateTime(1998, 1, 1) var result = from a in customers from o in a.Orders where o.OrderDate > new DateTime(1998, 1, 1) select new { a.CustomerID, o.OrderID, OrderDate = o.OrderDate.ToString("yyyy-MM-dd") }; Print(result); }
/// <summary> /// 查询表达式 /// </summary> /// <param name="x"></param> public void Show(int x) { var list = new ProductList(); var customers = list.GetCustomerList(); Console.WriteLine(); Console.WriteLine("SelectMany_Compound_from_Assignment 查询表达式"); //total >= 2000.0M var result = from c in customers from o in c.Orders where o.Total >= 2000.0M select new { c.CustomerID, o.OrderID, total = o.Total }; Print(result); }
/// <summary> /// 点标记 /// </summary> public void Show() { var list = new ProductList(); var customers = list.GetCustomerList(); Console.WriteLine(); Console.WriteLine("SelectMany_Indexed 点标记"); //Pairs where a < b: var result = customers.SelectMany((cust, index) => cust.Orders.Select(o => "Customer #" + (index + 1) + " has an order with OrderID " + o.OrderID) ); Print(result); }
/// <summary> /// 查询表达式 /// </summary> /// <param name="x"></param> public void Show(int x) { var list = new ProductList(); var customers = list.GetCustomerList(); DateTime cutoffDate = new DateTime(1997, 1, 1); Console.WriteLine(); Console.WriteLine("SelectMany_Indexed 查询表达式"); //o.OrderDate >= cutoffDate //var result = from c in customers // where c.Region == "WA" // from o in c.Orders // where o.OrderDate >= cutoffDate // select new { c.CustomerID, o.OrderID }; //Print(result); }
/// <summary> /// 点标记 /// </summary> public void Show() { var list = new ProductList(); var products = list.GetProductList(); var customers = list.GetCustomerList(); var productFirstChars = from p in products select p.ProductName[0]; var customerFirstChars = from c in customers select c.CompanyName[0]; Console.WriteLine(); Console.WriteLine("Intersect_2 点标记"); //Numbers < 5: var result = productFirstChars.Intersect(customerFirstChars).OrderBy(x => x); Print(result); }
/// <summary> /// 查询表达式 /// </summary> /// <param name="x"></param> public void Show(int x) { var list = new ProductList(); var customers = list.GetCustomerList(); Console.WriteLine(); Console.WriteLine("GroupBy_Nested 查询表达式"); //n % 5 var result = (from w in customers select new { w.CompanyName, YearGroups = from o in w.Orders group o by o.OrderDate.Year into yg select new { Year = yg.Key, MonthGroups = from o in yg group o by o.OrderDate.Month into mg select new { Month = mg.Key, Orders = mg } } }).ToList(); Print(result); }