How do I filter my Linq-to-SQL query so that it only shows records that aren’t referenced (via a FK) in another table?
So for example, I had two tables: TableA and TableB. TableB had a FK referencing TableA. I want to select all rows from TableA that have no records in TableB referencing it.
In raw T-SQL, I can do:
SELECT * FROM TableA
WHERE NOT EXISTS (SELECT * FROM TableB WHERE TableA._id = TableB.fk_tablea_id)
In raw MySQL, I can do a left join and use the ISNULL() function in the where clause.
I’m not sure of the best way to do this with LINQ to SQL.
You can do the below: