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# 控制相机设备 2022-01-01
- 获取C#保存对话框的文件路径 2022-01-01
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
- C# 9 新特性——record的相关总结 2023-04-03
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- 如果条件可以为空 2022-01-01
- 将数据集转换为列表 2022-01-01
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
- 重新排序 WPF TabControl 中的选项卡 2022-01-01
