在 Linq to SQL 中使用 OR 来连接多个列上的 EQUALS

问题描述 投票:0回答:1

在连接 2 个表(T2 和 T3)时,我找不到使用“OR”连接第三个表的正确语法 - 在下面的代码中 - 如何在具有 4 个不同列的 t3 表上添加“或等于”?

 List<Tuple<Match, Match_Players, Competition>> res = (from t1 in _context.Competitions.AsEnumerable()
                join t2 in _context.Match_Players.AsEnumerable() on (t1.Club_Id, t1.Comp_Id) equals (t2.Club_Id, t2.Comp_Id)
                join t3 in _context.Matches.AsEnumerable() on (t2.Club_Id, t2.Comp_Id, t2.Team_Id, t2.Match_Id)
                    equals (t3.Club_Id, t3.Comp_Id, t3.Team_Id_Home, t3.Match_Id)
                    ***or
                    equals(t3.Club_Id, t3.Comp_Id, t3.Team_Id_away, t3.Match_Id)***
                where t1.Club_Id == club_id && t1.Comp_Inactive == false && t2.UserId == player_id && t2.Player_Starter != 2
                select new Tuple<Match, Match_Players, Competition>(t3, t2, t1)).ToList();

感谢您的帮助 - 非常感谢

c# linq
1个回答
0
投票

您不能在

or
子句中使用
join
关键字。 相反,您可以在
or
子句中使用
||
where
来过滤掉不满足条件的条件。

另请参阅:LINQ 与 OR 结合

© www.soinside.com 2019 - 2024. All rights reserved.