DEV Community

Discussion on: Using C# LINQ API to perform SQL IN logic at WHERE clause

Collapse
 
dmfay profile image
Dian Fay • Edited

I stopped writing C# right as LINQ got popular so I don't know it too well but I believe this does store the list of emails in memory.

In SQL you could do this:

SELECT c.*
FROM customers AS c
JOIN users AS u ON u.email = c.email
WHERE u.customer_id IS NULL

and achieve the same result without a subquery. I don't know how you'd go about translating that to LINQ though.

Collapse
 
alexruzenhack profile image
Alex Ruzenhack • Edited

It's true! But the tables are in different contexts, which means they are in different databases. So, it's not possible to make a JOIN between them.

Thread Thread
 
dmfay profile image
Dian Fay

My condolences :)

Collapse
 
rafalpienkowski profile image
Rafal Pienkowski

In my opinion, this is a better approach, which doesn't require an additional call to the database and doesn't require to store entities in the memory (which could have terrible results in case of a huge collection).
And of course, it is available in LINQ.