您的位置:首页 > 其它

LINQ中实现not in查询

2015-11-06 10:42 204 查看

在实际项目中,经常会用到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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  linq