Using Linq2db
and Ms Access
I want to select all sectors that don't have targets ergo I want to execute left outer join with exclusion:
Dim q10 = From s In db.Sectors
From t In db.Targets.Where(Function(f) f.id_sector = s.Id).DefaultIfEmpty
Where t Is Nothing
Select s
Linq2db
resolves this as:
-- Access
SELECT
[t2].[Id],
[t2].[Name]
FROM
[tblSector] [t2]
LEFT JOIN [tblTarget] [t1] ON ([t1].[id_sector] = [t2].[Id])
WHERE
[t1].* IS NULL <=========== HERE
which obviously is wrong.
I tried also:
Dim q10 = From s In db.Sectors
From t In db.Targets.Where(Function(f) f.id_sector = s.Id And f Is Nothing).DefaultIfEmpty
Select s
receiving:
-- Access
SELECT
[t2].[Id],
[t2].[Name]
FROM
[tblSector] [t2]
LEFT JOIN [tblTarget] [t1] ON ([t1].[id_sector] = [t2].[Id] AND [t1].* IS NULL) <=========== HERE
Summarize, I need:
SELECT
[t2].[Id],
[t2].[Name]
FROM
[tblSector] [t2]
LEFT JOIN [tblTarget] [t1] ON ([t1].[id_sector] = [t2].[Id])
WHERE
[t1].[id_sector] IS NULL
How to write in condition Where t1.id_sector Is Nothing
(id_sector is FK
so it is Integer
so it can't be Nothing
.