为了简单起见我有2个表:
Table1 has UserId Email
Table2 has UserId Score
我想过滤掉所有分数> 10.但是,Table2不保证其中包含任何用户。 UserId是Table2上的PK和FK。 UserId是表1上的PK。
我的问题是我需要将所有分数都存在,然后检查它们。
答案 0 :(得分:1)
var q =
from user in Table1
join s in Table2 on user.UserId equals score.UserId into lscore
from score in lscore.DefaultIfEmpty()
where score == null || lscore.score < 10
select new { userId = user.userid, email = user.Email, Score = score == null ? 0 : lscore.score };