public void LinqQuery03() { int valSum = 300; var customers = new LinqSamples().GetCustomerList(); var result = customers.Where(c => c.Orders.All(o => o.Total > valSum)).Where(o => o.Orders.Count() > 0); ObjectDumper.Write(result, 5); }
public void LinqQuery04() { var customers = new LinqSamples().GetCustomerList(); var result = customers.Where(c => c.Orders.Count() > 0).OrderBy(y => y.Orders.First().OrderDate.Year).ThenBy(m => m.Orders.First().OrderDate.Month).ThenByDescending(s => s.Orders.Sum(cust => cust.Total)).ThenBy(name => name.CompanyName); var result2 = from c in customers where c.Orders.Count() > 0 orderby c.Orders.First().OrderDate.Year, c.Orders.First().OrderDate.Month, c.Orders.Sum(s => s.Total) descending, c.CompanyName select c; foreach (var item in result) { Console.WriteLine(item.Orders.First().OrderDate.Year + " month " + item.Orders.First().OrderDate.Month + " sum " + item.Orders.Sum(s => s.Total) + " Name " + item.CompanyName); } }
public void LinqQuery01() { var customers = new LinqSamples().GetCustomerList(); decimal rangesum = 5000; var sel_customer = customers.Where(x => x.Orders.Sum(s => s.Total) < rangesum); foreach (var item in sel_customer) { Console.WriteLine($"Company: \"{item.CompanyName.ToUpper()}\", Orders Sum = {item.Orders.Sum(s => s.Total)}"); ObjectDumper.Write(item, 1); } ObjectDumper.Write(sel_customer, 1); }