什么是语法内加入LINQ到SQL? [英] What is the syntax for an inner join in LINQ to SQL?
本文介绍了什么是语法内加入LINQ到SQL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在写的LINQ to SQL语句和放大器;我只是以后在C#中有一个正常的内部标准语法加入开的条款。
也就是说你如何重新present这在LINQ到SQL:
SELECT * FROM表1
内部联接表2上table1.field = table2.field
编辑:实时查询来获取经销商所有联系人:
选择代理商联系。*
从经销商
内部联接代理商联系上Dealer.DealerID = DealerContact.DealerID
解决方案
这是这样:
从T1在db.Table1
加入T2在db.Table2上t1.field等于t2.field
选择新{t1.field2,t2.field3}
这将是不错的明智名和字段的表一个更好的例子。 :)
更新
我觉得对于您的查询,这可能是更合适的:
VAR dealercontacts =从代理商联系接触
加盟经销商经销商对contact.DealerId等于dealer.ID
选择接触;
既然你要找的联系人,而不是经销商。
I'm writing a linq to sql statement & I'm just after the standard syntax for a normal inner join with an 'on' clause in C#.
ie how do you represent this in LINQ to SQL?:
select * from table1
inner join table2 on table1.field = table2.field
EDIT: Real query to get all contacts for a dealer:
select DealerContact.*
from Dealer
inner join DealerContact on Dealer.DealerID = DealerContact.DealerID
解决方案
It goes something like:
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. :)
Update
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到SQL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文