检查Linq查询中可能的空值

检查Linq查询中可能的空值,linq,linq-to-sql,Linq,Linq To Sql,为了简单起见,我有两张表: Table1 has UserId Email Table2 has UserId Score 我想过滤掉所有大于10的分数。但是,不能保证表2中有任何用户。UserId是表2中的PK和FK。UserId是表1上的一个PK 我的问题是,我需要得到所有分数,然后检查它们 见 var q= 来自表1中的用户 将表2中user.UserId等于score.UserId的s加入到lscore中 来自lscore.DefaultIfEmpty()中的分数 其中score==n

为了简单起见,我有两张表:

Table1 has UserId Email
Table2 has UserId Score
我想过滤掉所有大于10的分数。但是,不能保证表2中有任何用户。UserId是表2中的PK和FK。UserId是表1上的一个PK

我的问题是,我需要得到所有分数,然后检查它们

var q=
来自表1中的用户
将表2中user.UserId等于score.UserId的s加入到lscore中
来自lscore.DefaultIfEmpty()中的分数
其中score==null | | lscore.score<10
选择新建{userId=user.userId,email=user.email,Score=Score==null?0:lscore.Score};

不清楚你想做什么,你做了什么,或者你遇到了什么问题;我的胡思乱想只是胡思乱想。我的主要问题是你的桌子结构不稳定。谢谢。我想我需要一个左外连接。但是,我不知道如何对值进行检查。实际上,这个查询不起作用。lscore没有分数,也许你的意思是分数。我现在正在测试这个。再次感谢。
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 };