日期:2014-05-20 浏览次数:20953 次
using (AdventureWorksEntities AWEntities = new AdventureWorksEntities()) { ObjectQuery<SalesOrderHeader> orders = AWEntities.SalesOrderHeader; ObjectQuery<SalesOrderDetail> details = AWEntities.SalesOrderDetail; var query = from order in orders join detail in details on order.SalesOrderID equals detail.SalesOrderID into orderGroup select new { CustomerID = order.SalesOrderID, OrderCount = orderGroup.Count() }; foreach (var order in query) { Console.WriteLine("CustomerID: {0} Orders Count: {1}", order.CustomerID, order.OrderCount); } }