2016-06-28 69 views
1

我正在寫linq查詢,需要從左表中獲取記錄總是事件,如果沒有記錄在右表中。我寫了linq查詢。在這種情況下,右表可能由空值組成,我收到錯誤。 如何在子句中檢查空條件,而不是在where子句中。如果我使用where子句檢查空值,它會得到零記錄,但我需要所有左表記錄。如何檢查linq中的空值左連接條件insted在哪裏條件

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 

回答

0

爲保持left outer join語義的一般規則是之前應用右表濾波器聯接:

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() 
+0

謝謝它解決了我的問題 –