LINQ中实现not in查询

来源:互联网 发布:体检 知乎 编辑:程序博客网 时间:2024/06/14 01:11


在实际项目中,经常会用到not in 的查询操作,下面介绍 LINQ中实现not in查询 的实例



from c in dc.Customerswhere !(from o in dc.Ordersselect 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.Productswhere ! (new int[] {1,2}).Contains(p.CategoryID)select p;




文章转载自: LINQ中实现not in查询   http://www.studyofnet.com/news/1092.html


0 0
原创粉丝点击