.NET[C#]LINQ如何实现NOT IN的查询?
方案一
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 );
方案二
var answer = list1.Except(list2);
方案三
from item1 in List1
where !(list2.Any(item2 => item2.Email == item1.Email))
select item1;
方案四
var itemIds = inMemoryList.Select(x => x.Id).ToArray();
var otherObjects = context.ItemList.Where(x => !itemIds.Contains(x.Id));
方案五
var NotInRecord =list1.Where(p => !list2.Any(p2 => p2.Email == p.Email));
方案六
list1.RemoveAll(Item => list2.Contains(Item));
方案七
var secondEmails = (from item in list2
select new { Email = item.Email }
).ToList();
var matches = from item in list1
where !secondEmails.Contains(item.Email)
select new {Email = item.Email};
版权声明:本作品系原创,版权归码友网所有,如未经许可,禁止任何形式转载,违者必究。
发表评论
登录用户才能发表评论, 请 登 录 或者 注册