entity framework进行一对多的联合查询
时间:2010-10-28 来源:xuesky
1 using (AdventureWorksEntities AWEntities = new AdventureWorksEntities())
2 {
3 ObjectQuery<SalesOrderHeader> orders = AWEntities.SalesOrderHeader;
4 ObjectQuery<SalesOrderDetail> details = AWEntities.SalesOrderDetail;
5
6 var query =
7 from order in orders
8 join detail in details
9 on order.SalesOrderID
10 equals detail.SalesOrderID into orderGroup
11 select new
12 {
13 CustomerID = order.SalesOrderID,
14 OrderCount = orderGroup.Count()
15 };
16
17 foreach (var order in query)
18 {
19 Console.WriteLine("CustomerID: {0} Orders Count: {1}",
20 order.CustomerID,
21 order.OrderCount);
22 }
23 }
24
25
相关阅读 更多 +