简体   繁体   English

LINQ加入多个领域

[英]LINQ Join on multiple fields

What would be the equivalent of the following T-SQL query in L2E using Lambda expressions? 使用Lambda表达式在L2E中等效的以下T-SQL查询是什么?

Select * from a INNER JOIN b on a.Foo = b.Foo OR a.Foo = b.Bar  

I want to join a and b when a.Foo equal to b.Foo OR b.Bar a.Foo等于b.Foob.Bar时,我想加入a和b

Thanks. 谢谢。

You can't do an "or" style join in LINQ with an actual join clause. 您不能在LINQ中使用实际的join子句进行“或”样式连接。 All join clauses in LINQ are equijoins. LINQ中的所有连接子句都是equijoins。 The closest you can come is a where clause: 你最接近的是where子句:

var query = from a in A
            from b in B
            where a.Foo == b.Foo || a.Foo == b.Bar
            select new { a, b };

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM