linq to sql:连接同一表中的多个列

问题描述:

如何通过Linq内部联接来自同一表的多个列?

How do I inner join multiple columns from the same tables via Linq?

例如: 我已经有了这个...

For example: I already have this...

join c in db.table2 on table2.ID equals table1.ID

我需要添加这个...

I need to add this...

join d in db.table2 on table2.Country equals table1.Country 

您可以将查询放在Where子句中,而不使用联接运算符.

You can put your query inside a Where clause instead of using the join operator.

join运算符在VB.NET中支持多个子句,但在C#中不支持.

The join operator supports multiple clauses in VB.NET, but not C#.

或者,您可以使用ANSI-82风格的"SQL"语法,例如:

Alternatively, you can use the ANSI-82 style of 'SQL' syntax, e.g.:

from t1 in table1
from t2 in table1
where t1.x == t2.x
&& t1.y == t2.y