linq to sql:连接同一表中的多个列 [英] linq to sql: join multiple columns from the same table

查看:130
本文介绍了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

这篇关于linq to sql:连接同一表中的多个列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆