linq group by

 

var customers = BuildCustomers();

var results = 
	from c in customers
	from o in c.Orders
	where c.FirstName.Length >=5 &&
		o.Product == "Milk"
	group by c into avg
	select new { 
				avg.Key.FirstName, avg.Key.LastName,
				avg =avg.Average( o => o.Quantity )
			};

ObjectDumper.Write(results, Writer );

 

 

 

 

posted @ 2010-12-09 14:56  庚武  Views(315)  Comments(0Edit  收藏  举报