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));
Source: stackoverflow.com
Related Query
- EF - AND NOT EXISTS (SELECT 1 ...) with Entity Framework
- SELECT NEW with a potentially null field using LINQ and Entity Framework
- How to select a query with multiple columns and put it into variables using Entity Framework and ASP.NET?
- How to select multiple columns with entity framework and display it with textBlocks?
- Entity Framework select multiple columns and return the one that is not null
- Entity Framework Select with Include + Group By Count + Paging and Projection
- Difference between Select and Where in Entity Framework
- how to use entity framework to group by date not date with time
- How to avoid memory overflow when querying large datasets with Entity Framework and LINQ
- Entity Framework - Linq query with order by and group by
- Use a Inline Table-Valued Functions with Linq and Entity Framework Core
- Entity Framework Group By with Max Date and count
- Always encrypted with Entity Framework and Includes fails to materialise query
- Entity framework and Exists clause
- Trouble with Entity Framework Linq Query: runs instantly in SSMS and 8-10s in EF LINQ
- Entity framework `AsNoTracking` is not working with anonymous projection
- Getting stored procedure output parameter with LINQ and Entity Framework
- jQuery Datatable with MVC 5 and Entity Framework
- Entity Framework with Oracle using odp.net not taking parameters in linq query
- Add leading zeros with LINQ and Entity Framework
- Using async with Entity Framework select list of type IQueryable<T>
- Forcing Entity Framework to not generate NCLOB's when building Linq-to-Sql Code (Model First)
- Nested expression building with linq and Entity Framework
- Entity Framework - Select specific columns and return strongly typed without losing cast
- Wrong select query generated with Entity Framework (mysterious extra column)
- DataTable select with LiNQ and check is there duplicate rows or not
- Is it possible to get Entity Framework to recognize objects that have been created and not yet saved in database?
- ASP NET CORE Entity Framework Select with GroupBy Id
- Why is Entity Framework .ToList() with .Include very slow and how can I speed it up?
- How to map Integer to String with AutoMapper 3 and Entity Framework
More Query from same tag
- Linq Anonymous type members must be declared in Sub Query
- using Lambda expression for implementing a query in many-to-many relation tables
- How to turn LINQ query into anonymous type
- C# Count removed nodes
- Linq Newbie. Can I write this Linq query more concise?
- Getting first time-In and last time-Out covering the following day based on a date Collection using linq
- How to get List of Properities from System.Collections.IEnumerable using LINQ C#
- pass multiple data as a list to View in MVC
- XNamespace url is written in XAttribute when I create my XML
- Linq to get List with most elements and biggest diff inside it's elements from a List<List<int>>
- Perform group and join using LINQ
- How to query against Dictionary contents in Azure CosmosDB/DocumentDB?
- LINQ to Object Help
- Linq Syntax Any()
- How can I query the range of date which one product has not been ordered? (LINQ)
- Remove items from one list if they contain strings from another list
- LINQ, where clause if field is int?
- Including a second table Linq to Sql
- Extendable Linq Query
- SubString editing
- Converting conditionally built SQL where-clause into LINQ
- custom string sorter
- Convert List.Contains to Expression Tree
- Unit test IObservable<T> with ObserveOnDispatcher
- Need to compare 2 generic list of same type based on dynamic columns/fields that will be know at run time
- How do I programmatically translate a LINQ query to readable English text that correctly describes the linq expression?
- The query contains references to items defined on a different data context
- How do I use Group By and MAX in Linq to return multiple rows?
- Read XML to linq object, then create XML
- Why is Entity Framework core loading entity's relations without adding include