score:28

Accepted answer

the direct equivalent linq construct of sql not exists (...) is !any(...).

so

select p.*
from produtos p
where p.enterpriseid = '00000000000191' and p.productid <> '14' 
and not exists (select 1 from similarproducts sp where sp.similarid = 
p.productid)

translates to

from p in db.produtos
where p.enterpriseid = "00000000000191" && p.productid != 14 
&& !db.similarproducts.any(sp => sp.similarid == p.productid)
select p;

score:-1

ef contains => sql in() : iterate all items (slower)

ef any => sql exists() : iterate until conditions return true (faster)

 await appdbcontext.mastertable
.where(m => !m.detailtable.any(d => d.masterid == m.id))
.tolistasync();

score:10

you can use contains with any which will work like not exists in sql. like this:

var restuls = db.produtos.where(p => p.enterpriseid == '00000000000191' 
                 && p.productid != 14 
                 && !db.similarproducts.any(sp =>sp.similarid == p.productid));

Related Query

More Query from same tag