Mega Code Archive

 
Categories / C# Book / 04 LINQ
 

0498 Count - Nested

public void Linq76() { List<Customer> customers = GetCustomerList(); var orderCounts = from c in customers select new { c.CustomerID, OrderCount = c.Orders.Count() }; ObjectDumper.Write(orderCounts); } Result CustomerID=ALFKI CustomerID=ANATR CustomerID=ANTON CustomerID=AROUT CustomerID=BERGS CustomerID=BLAUS CustomerID=BLONP CustomerID=BOLID CustomerID=BONAP CustomerID=BOTTM CustomerID=BSBEV CustomerID=CACTU CustomerID=CENTC CustomerID=CHOPS CustomerID=COMMI CustomerID=CONSH CustomerID=DRACD CustomerID=DUMON CustomerID=EASTC CustomerID=ERNSH CustomerID=FAMIA CustomerID=FISSA CustomerID=FOLIG CustomerID=FOLKO CustomerID=FRANK CustomerID=FRANR CustomerID=FRANS CustomerID=FURIB CustomerID=GALED CustomerID=GODOS CustomerID=GOURL CustomerID=GREAL CustomerID=GROSR CustomerID=HANAR CustomerID=HILAA CustomerID=HUNGC CustomerID=HUNGO CustomerID=ISLAT CustomerID=KOENE CustomerID=LACOR CustomerID=LAMAI CustomerID=LAUGB CustomerID=LAZYK CustomerID=LEHMS CustomerID=LETSS CustomerID=LILAS CustomerID=LINOD CustomerID=LONEP CustomerID=MAGAA CustomerID=MAISD CustomerID=MEREP CustomerID=MORGK CustomerID=NORTS CustomerID=OCEAN CustomerID=OLDWO CustomerID=OTTIK CustomerID=PARIS CustomerID=PERIC CustomerID=PICCO CustomerID=PRINI CustomerID=QUEDE CustomerID=QUEEN CustomerID=QUICK CustomerID=RANCH CustomerID=RATTC CustomerID=REGGC CustomerID=RICAR CustomerID=RICSU CustomerID=ROMEY CustomerID=SANTG CustomerID=SAVEA CustomerID=SEVES CustomerID=SIMOB CustomerID=SPECD CustomerID=SPLIR CustomerID=SUPRD CustomerID=THEBI CustomerID=THECR CustomerID=TOMSP CustomerID=TORTU CustomerID=TRADH CustomerID=TRAIH CustomerID=VAFFE CustomerID=VICTE CustomerID=VINET CustomerID=WANDK CustomerID=WARTH CustomerID=WELLI CustomerID=WHITC CustomerID=WILMK CustomerID=WOLZA OrderCount=6 OrderCount=4 OrderCount=7 OrderCount=13 OrderCount=18 OrderCount=7 OrderCount=11 OrderCount=3 OrderCount=17 OrderCount=14 OrderCount=10 OrderCount=6 OrderCount=1 OrderCount=8 OrderCount=5 OrderCount=3 OrderCount=6 OrderCount=4 OrderCount=8 OrderCount=30 OrderCount=7 OrderCount=0 OrderCount=5 OrderCount=19 OrderCount=15 OrderCount=3 OrderCount=6 OrderCount=8 OrderCount=5 OrderCount=10 OrderCount=9 OrderCount=11 OrderCount=2 OrderCount=14 OrderCount=18 OrderCount=5 OrderCount=19 OrderCount=10 OrderCount=14 OrderCount=4 OrderCount=14 OrderCount=3 OrderCount=2 OrderCount=15 OrderCount=4 OrderCount=14 OrderCount=12 OrderCount=8 OrderCount=10 OrderCount=7 OrderCount=13 OrderCount=5 OrderCount=3 OrderCount=5 OrderCount=10 OrderCount=9 OrderCount=0 OrderCount=6 OrderCount=10 OrderCount=6 OrderCount=9 OrderCount=13 OrderCount=28 OrderCount=5 OrderCount=18 OrderCount=12 OrderCount=11 OrderCount=10 OrderCount=5 OrderCount=6 OrderCount=31 OrderCount=9 OrderCount=7 OrderCount=4 OrderCount=9 OrderCount=12 OrderCount=4 OrderCount=3 OrderCount=5 OrderCount=10 OrderCount=7 OrderCount=3 OrderCount=11 OrderCount=10 OrderCount=4 OrderCount=10 OrderCount=15 OrderCount=9 OrderCount=14 OrderCount=8 OrderCount=7