如何检查 linq 左连接条件中的空值而不是 where 条件

how to check null values in linq left join condition insted in where condition

我正在编写需要从左侧获取记录的 linq 查询 table 如果右侧 table 没有记录,则总是事件。我为 that.Right table 编写的 linq 查询可能包含空值,在这种情况下我收到错误。 如何在 on 子句中而不是在 where 子句中检查空条件。如果我使用 where 子句检查空值,它会得到零条记录,但我需要所有剩余的 table 条记录。

 join sfs in db.SubmissionFileUploadSummaries on new { sub.CollectionId, districtid, tbl.Tablename } equals new { CollectionId = (int)sfs.CollectionId, districtid = (int)sfs.OrganizationId, Tablename = sfs.TableName }
             into sfslist
             from sfssub in sfslist.DefaultIfEmpty()
             where sfssub.CollectionId!=null

保持 left outer join 语义的一般规则是在 连接之前应用正确的 table 过滤器:

join sfs in (from sfs in db.SubmissionFileUploadSummaries
             where sfs.CollectionId != null
             select sfs)  
    on new { sub.CollectionId, districtid, tbl.Tablename }
    equals new { CollectionId = (int)sfs.CollectionId, districtid = (int)sfs.OrganizationId, Tablename = sfs.TableName }
into sfslist
from sfssub in sfslist.DefaultIfEmpty()