使用LINQ需要有关内部连接查询的帮助

时间:2009-03-09 10:23:38

标签: c# linq-to-xml outer-join

我在XML数据集中有两个表。 T1,T2。每个表都有一个ID列。

T1有一个客户列表 T2有一个订单列表

我想构建一个LINQ查询,该查询只返回没有订单的客户的ID。换句话说,T2表中不存在客户ID。

哦,是的,我正在使用C#

谢谢!

3 个答案:

答案 0 :(得分:9)

这需要外部联接并检查null。

var result = from c in Customers
             join d in Details on d.CustomerID equals c.ID into g
             where !g.Any()
             select c;

答案 1 :(得分:6)

我认为这会有效(请适应您的数据集):

var query = from c in T1
            where !(from o in T2 select o.CustomerID)
            .Contains(c.CustomerID)
            select c;

答案 2 :(得分:1)

你只需要使用where子句和all:

T1.Where( item1 => T2.All( item2 => item1.ID != item2.ID ) );
相关问题