LINQ – 哪里不存在
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 )
试试这个Not Any
模式。
var query = db.table1 .Where(t1 => !db.table2 .Any(t2 => t2.cat == t1.cat && t2.julianDte < t1.julianDte) );
查询@David B的答案的语法版本(with!Any倒数为全部):
from t1 in db.Table1 where db.Table2.All(t2 => t1.cat != t2.cat || t2.julianDte >= t1.julianDte) select new { t1.appname, t1.julianDte, t1.cat };
from t1 in Context.table1DbSet let ok = (from t2 in Context.table2DbSet where t2.Idt1 = t1.Idt1 && t1.DateValid.HasValue ).Any() where t1.Active && !ok