What is the syntax for an inner join in LINQ to SQL?(LINQ to SQL 中的内部联接的语法是什么?)
问题描述
我正在编写一个 LINQ to SQL 语句,并且我正在使用 C# 中带有 ON
子句的普通内部连接的标准语法.
I'm writing a LINQ to SQL statement, and I'm after the standard syntax for a normal inner join with an ON
clause in C#.
您如何在 LINQ to SQL 中表示以下内容:
How do you represent the following in LINQ to SQL:
select DealerContact.*
from Dealer
inner join DealerContact on Dealer.DealerID = DealerContact.DealerID
推荐答案
它是这样的:
from t1 in db.Table1
join t2 in db.Table2 on t1.field equals t2.field
select new { t1.field2, t2.field3}
如果您的表具有合理的名称和字段以作为更好的示例,那就太好了.:)
It would be nice to have sensible names and fields for your tables for a better example. :)
更新
我认为对于您的查询,这可能更合适:
I think for your query this might be more appropriate:
var dealercontacts = from contact in DealerContact
join dealer in Dealer on contact.DealerId equals dealer.ID
select contact;
因为您是在寻找联系人,而不是经销商.
Since you are looking for the contacts, not the dealers.
这篇关于LINQ to SQL 中的内部联接的语法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:LINQ to SQL 中的内部联接的语法是什么?


- C#MongoDB使用Builders查找派生对象 2022-09-04
- C# 中多线程网络服务器的模式 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 输入按键事件处理程序 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01