如何使用LINQ实现左排除JOIN? [英] How to achieve Left Excluding JOIN using LINQ?

查看:52
本文介绍了如何使用LINQ实现左排除JOIN?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用LINQ实现左排除JOIN?

How to achieve Left Excluding JOIN using LINQ?

SQL 中:

SELECT <select_list> 
FROM Table_A A
LEFT JOIN Table_B B
ON A.Key = B.Key
WHERE B.Key IS NULL

推荐答案

您需要DefaultIfEmpty()作为LEFT JOIN,然后您可以检查所连接的值是否为null:

You need DefaultIfEmpty() for the LEFT JOIN, then you can check if the joined value is null:

var result = from a in Table_A
             join b in Table_B on a.Key equals b.Key into j
             from b in j.DefaultIfEmpty()
             where b == null
             select new { ... };

这篇关于如何使用LINQ实现左排除JOIN?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆