LINQ的不包含动态查询

问题描述:

可能重复:
Linq to SQL “not like” operatorLINQ的不包含动态查询

我怎么能写使用不包含动态LINQ查询?

我使用.Contains()而不是像。但是我应该用什么来代替not like

只是在包含条件之前使用!。像

var myProducts = from p in products 
        where !productList.Contains(p.ID) 
        select p; 
+0

我只是把标记放在错误的地方。感谢@habib – 2012-07-25 11:36:27

一些像这样的东西应该帮助...

YourDataContext dc = new YourDataContext(); 
    var query =  
     from c in dc.Customers  
     where !(from o in dc.Orders  
       select o.CustomerID)  
       .Contains(c.CustomerID)  
     select c; 

使用!运营商。像这样:

private List<int> iList = new List<int> 
      { 
       1,2,3,4,5,6,7,8,9 
      }; 

    if (!iList.Contains(888)) 
       { 

       }