在实际项目中,经常会用到not in 的查询操作,下面介绍 LINQ中实现not in查询 的实例
from c in dc.Customers
where !(from o in dc.Orders
select o.CustomerID).Contains(c.CustomerID)
select c;
var query = from c in _opvRepository.Table
join a in _orderRepository.Table on c.OrderId equals a.Id
join p in _pvRepository.Table on c.ProductVariantId equals p.Id
join e in _productRepository.Table on p.ProductId equals e.Id
where a.CustomerId == customerId & !(from s in _productReviewRepository.Table select s.ProductId).Contains(a.CustomerId & p.ProductId)
select new CustomerChapter()
{
Name = p.Name,
ProdcutName = e.Name,
CreatedOn = a.CreatedOnUtc,
ProductId = p.ProductId,
Id = a.CustomerId,
};
var queryResult = from p in db.Products
where ! (new int[] {1,2}).Contains(p.CategoryID)
select p;
文章转载自: LINQ中实现not in查询 http://www.studyofnet.com/news/1092.html