如果你想写得简单,但是不在乎性能,你可以写
from x in table1
join y in table2 on x.MzRegId equals y.ID
from z in table3
x.MzRegId == table3.MzRegId || y.CardNo == z.CardNo
select new { x, y, z }
在table3数据量大的时候性能会比较差,反之无所谓。
或者你干脆用sql。
你看清楚了, “ OR ” table2.CardNo = table3.CardNo 这里用的or 不是用and连接的[/quote]
or更简单,可以这么写
(from x in table1
join y in table2 on x.MzRegId equals y.ID
join z in table3 on x.MzRegId equals z.MzRegId
select new { x, y, z }).Union
(from x in table1
join y in table2 on x.MzRegId equals y.ID
join z in table3 on y.CardNo equals z.CardNo
select new { x, y, z })[/quote]
用Union查询太复杂了,我贴出来的只是一部分,还有一大堆东西,到时写好后可读性就太低了[/quote]
还有没有更好的办法??
你看清楚了, “ OR ” table2.CardNo = table3.CardNo 这里用的or 不是用and连接的[/quote]
or更简单,可以这么写
(from x in table1
join y in table2 on x.MzRegId equals y.ID
join z in table3 on x.MzRegId equals z.MzRegId
select new { x, y, z }).Union
(from x in table1
join y in table2 on x.MzRegId equals y.ID
join z in table3 on y.CardNo equals z.CardNo
select new { x, y, z })[/quote]
用Union查询太复杂了,我贴出来的只是一部分,还有一大堆东西,到时写好后可读性就太低了
你看清楚了, “ OR ” table2.CardNo = table3.CardNo 这里用的or 不是用and连接的[/quote]
or更简单,可以这么写
(from x in table1
join y in table2 on x.MzRegId equals y.ID
join z in table3 on x.MzRegId equals z.MzRegId
select new { x, y, z }).Union
(from x in table1
join y in table2 on x.MzRegId equals y.ID
join z in table3 on y.CardNo equals z.CardNo
select new { x, y, z })
from x in table1
join y in table2 on x.MzRegId equals y.ID
join z in table3 on new { a = x.MzRegId, b = y.CardNo } equals new { a = z.MzRegId, b = z.CardNo }
select new { x, y, z }