LINQ联同或条件3个表 [英] linq join 3 tables with or condition
问题描述
我需要创建一个LINQ声明与3表和OR条件。
I need to create a statement in LINQ with 3 tables and OR condition.
我的函数接收一个整数,让我们把它叫做 intZ
。我有3个表:表A
, tableB的
和表C
。
My function receives an integer, lets call it intZ
. I have 3 tables: tableA
, tableB
and tableC
.
表A
有列 INT1
, INT2
和 INTB
。 INTB
是与 tableB的
。
问题: INT1
或 INT2
TABLEA的
可 intZ
和它匹配一个表C
记录。
problem: int1
or int2
of tableA
can be intZ
and it has to match with one tableC
record.
我需要一个或条件,但我不知道在哪里把它。它是否在where子句中去?或在平等条款?
I need an OR condition, but I have no idea where to place it. Does it go in the where clause? Or in the equals clause?
目前,我知道如何加入3个表,但条件是杀害我。
At the moment, I know how to join 3 tables, but the condition is killing me.
两者有什么方法可以创建在LINQ语句之间的区别? ?是否有一个性能的影响。
What is the difference between the two ways to create statements in linq? Is there a performance impact?
编辑:好吧,现在我觉得它更清楚。 intZ
必须与 INTC
从表C
和相关这个数字可以是 INT1
或 INT2
的表A
。
edit: Okay, now I think it's more clear. intZ
has to be related with intC
from tableC
, and this number can be int1
or int2
of tableA
.
推荐答案
只需将它添加到其中,
。在LINQ2SQL这将转换为内tableB的连接(带或)
Just add it to a Where
. In Linq2Sql this will be translated to an inner join (with or) on tableB
from a in tableA
from b in tableB.Where(x => x.A == a.A || x.B == a.B)
select new { a, b };
这篇关于LINQ联同或条件3个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!