开发者

Checking Possible Nulls Linq Query

I have for simplicity 2 tables:

Table1 has UserId Email
Table2 has UserId Score

I want to filter out all scores > 10. But, Table2 is not guaranteed to have any 开发者_如何转开发users in it. UserId is a PK and FK on Table2. UserId is a PK on table 1.

My issue is that I need to get all scores where they exist and then check them.


See Left Outer Join

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 };
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜