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 中的内部联接的语法是什么?
基础教程推荐
- Moq It.Is<>不匹配 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- WPF 模态进度窗口 2022-01-01
