你会如何​​做一个"不"使用LINQ查询? [英] How would you do a "not in" query with LINQ?

查看:114
本文介绍了你会如何​​做一个"不"使用LINQ查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有在两个集合财产电子邮件两个集合。我需要在电子邮件不会在第二个列表存在的第一个列表中的项目清单。随着SQL我只想用不,但我不知道LINQ的等价物。如何做呢?

I have two collections which have property Email in both collections. I need to get a list of the items in the first list where Email does not exist in the second list. With SQL I would just use "not in", but I do not know the equivalent in LINQ. How is that done?

到目前为止,我有一个连接,如...

So far I have a join, like...

var matches = from item1 in list1
join item2 in list2 on item1.Email equals item2.Email
select new { Email = list1.Email };

但我不能参加,因为我需要的差异和连接将失败。我需要使用某种方式包含或存在,我相信。我只是还没有找到一个例子来做到这一点呢。

But I cannot join since I need the difference and the join would fail. I need some way of using Contains or Exists I believe. I just have not found an example to do that yet.

推荐答案

我不知道这是否会帮助你,但..

I don't know if this will help you but..

NorthwindDataContext dc = new NorthwindDataContext();    
dc.Log = Console.Out;

var query =    
    from c in dc.Customers    
    where !(from o in dc.Orders    
            select o.CustomerID)    
           .Contains(c.CustomerID)    
    select c;

foreach (var c in query) Console.WriteLine( c );

从<一个href=\"http://programminglinq.com/blogs/marcorusso/archive/2008/01/14/the-not-in-clause-in-linq-to-sql.aspx\">The并非在LINQ条款由马尔科·鲁索SQL

这篇关于你会如何​​做一个&QUOT;不&QUOT;使用LINQ查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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