惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
D
Docker
Microsoft Security Blog
Microsoft Security Blog
Google DeepMind News
Google DeepMind News
M
MIT News - Artificial intelligence
P
Proofpoint News Feed
Engineering at Meta
Engineering at Meta
Y
Y Combinator Blog
Vercel News
Vercel News
F
Fortinet All Blogs
B
Blog
Recent Announcements
Recent Announcements
A
About on SuperTechFans
GbyAI
GbyAI
T
The Blog of Author Tim Ferriss
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - Franky
MongoDB | Blog
MongoDB | Blog
Stack Overflow Blog
Stack Overflow Blog
B
Blog RSS Feed
C
Check Point Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
V
Visual Studio Blog
月光博客
月光博客

博客园 - 风的传说

使用Entity Framework时要注意的一些性能问题 UML类图 软件项目的需求分析 MVC Models定义验证属性 增加asp.net应用程序性能的19种方法 - 风的传说 - 博客园 Entity Framework 批量删除 WPF 事件快速参考 [导入]非常不错的WCF入门文章,来自Artech [导入]Microsoft Expression Studio 2 简体中文正式版 [导入]C#开源持久层框架 [导入]Sql Server2005简单分页 [导入]提高C#编程水平的50个要点 [导入]New ASP.NET Charting Control: <asp:chart runat="server"/> [导入]asp.net 里的HttpHandler隐藏图片 [导入]c# oop思想 [导入]Pro ASP.NET 3.5 in C# 2008 [导入].Net3.5扩展方法实现对象JSON序列化 [导入]26句实用的英语 [导入]微软将 jQuery IntelliSense整合到Visual Studio [导入]08年最流行的十大SaaS术语 [导入]asp.net(c#)怎样将图片存入数据库? [导入]linq与xml
entity framework进行一对多的联合查询
风的传说 · 2010-10-28 · via 博客园 - 风的传说

以下示例针对 SalesOrderHeader 表和 SalesOrderDetail 表执行 GroupJoin 以查找每个客户的订单数。组联接等效于左外部联接,它返回第一个(左侧)数据源的每个元素(即使其他数据源中没有关联元素)。

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