LINQ - Where not exists

Amit picture Amit · May 22, 2009 · Viewed 37.5k times · Source

What is the equivalent of following statement in LINQ:

Select t1.appname, t1.julianDte, t1.cat 
From table1 t1 
Where NOT EXISTS 
   ( Select * 
     from table t2 
     where t1.cat = t2.cat AND t2.julianDte < t1.julianDte )

Answer

Amy B picture Amy B · May 22, 2009

Try this Not Any pattern.

var query = db.table1
.Where(t1 => !db.table2
  .Any(t2 => t2.cat == t1.cat && t2.julianDte < t1.julianDte)
);