2008-12-05 10 views

Respuesta

47
List<string> states = new List<string> { "CA", "IN", "MD" }; 
    var q = from a in authors 
      where !states.Contains(a.state) 
      select new { a.au_lname, a.state }; 

o

var q = authors.Where(a => !states.Contains(a.state)) 
        .Select(a => new { a.au_lname, a.state }); 
5

he aquí un ejemplo:

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); 
+0

Realmente no hay necesidad de hacer la subconsulta - la Contiene /! Contiene funcionará dentro del contexto de la consulta principal. – Rob

8

puede hacerlo por Contiene:

 var states = new[] {"CA", "IN", "MD"}; 
     var query = db.Authors.Where(x => !states.Contains(x.state)); 
4

Sí!

He aquí un ejemplo de código que ya había escrito:


      List<long> badUserIDs = new List { 10039309, 38300590, 500170561 }; 
      BTDataContext dc = new BTDataContext(); 
      var items = from u in dc.Users 
         where !badUserIDs.Contains(u.FbUserID) 
         select u; 

El SQL generado resulta ser:

{SELECT [t0].[UserID], [t0].[FbUserID], [t0].[FbNetworkID], [t0].[Name], FROM [dbo].[Users] AS [t0] WHERE NOT ([t0].[FbUserID] IN (@p0, @p1, @p2)) }

Cuestiones relacionadas