使用Linq2db
并且Ms Access
我想选择所有没有目标的扇区,因此我想执行带有排除的左外连接:
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
将此解决为:
-- Access
SELECT
[t2].[Id],
[t2].[Name]
FROM
[tblSector] [t2]
LEFT JOIN [tblTarget] [t1] ON ([t1].[id_sector] = [t2].[Id])
WHERE
[t1].* IS NULL <=========== HERE
这显然是错误的。
我也试过:
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
接收:
-- Access
SELECT
[t2].[Id],
[t2].[Name]
FROM
[tblSector] [t2]
LEFT JOIN [tblTarget] [t1] ON ([t1].[id_sector] = [t2].[Id] AND [t1].* IS NULL) <=========== HERE
总结一下,我需要:
SELECT
[t2].[Id],
[t2].[Name]
FROM
[tblSector] [t2]
LEFT JOIN [tblTarget] [t1] ON ([t1].[id_sector] = [t2].[Id])
WHERE
[t1].[id_sector] IS NULL
如何在条件下写入Where t1.id_sector Is Nothing
(id_sector 是FK
这样,Integer
所以它不可能是Nothing
.