2011-04-19 139 views
1

我有一个表应该通过电子邮件发送的人的用户名。当他们通过电子邮件发送时,一条记录会被添加到他们收到通知的另一张表格中。我需要编写一个linq查询,返回第一个表中不在notifed表中的任何记录。有人知道怎么做吗?谢谢。从一个表中选择不在另一个表中的行与linq

+0

我在这里找到答案 - http://programminglinq.com/blogs/marcorusso/archive/2008/01/14/the-not-in-clause-in-linq-to-sql.aspx – 2011-04-19 14:03:05

回答

0

第二个表的结果为空的外连接怎么样?

这是http://www.hookedonlinq.com/OuterJoinSample.ashx对于小的修改,只包括那些记录不匹配的记录:

string[] words = {"walking","walked","bouncing","bounced","bounce","talked","running"}; 
string[] suffixes = {"ing","ed","er","iest"}; 

var pairs = from word in words 
      from suffix in (from suffix in suffixes where word.EndsWith(suffix) select suffix).DefaultIfEmpty() 
      where String.IsNullOrEmpty(suffix) 
      select new {word, suffix}; 

Console.WriteLine(pairs); 
1

在伪代码,这是你应该做的(左连接)什么:

 List<int?> listA = new List<int?>() { 1, 2, 3, 4, 5, 6, 7 }; 
     List<int?> listB = new List<int?>() { 1, 2, 3, 4, 5 }; 

     var result = (from a in listA 
         join b in listB on a equals b into subset 
         from c in subset.DefaultIfEmpty() 
         where !c.HasValue 
         select a).ToList(); 

这将产生一个值为6和7的结果列表。

你应该看看这里的值,就好像它们在你的表中是PK和FK一样。

相关问题