2011-05-31 41 views
4

加入的問題,我有以下LINQ2SQL查詢:十字LINQ2SQL

From pc In DBContext.ProcessCodes 
Join c In DBContext.Cells On pc.idCell Equals c.idCell 
    Where pc.idType = "Cars" AndAlso 
      pc.Active = True AndAlso 
      c.Active = True 
    Select c 

出於某種原因,我得到一個交叉連接(笛卡爾乘積)時,我想我應該得到一個內部聯接。如果我在多個From中進行關鍵比較,我會得到同樣的結果。

我在做什麼錯?

+3

第一步可能是檢查出生成的SQL。 http://www.davidhayden.com/blog/dave/archive/2007/08/17/DataContextLogLoggingLINQToSQLOutputConsoleDebuggerOuputWindow.aspx – Keith 2011-06-03 20:22:51

回答

0

我認爲這可以幫助您:

From pc In DBContext.ProcessCodes 
From c In DBContext.Cells 
Where pc.idType = "Cars" AndAlso   
     pc.Active = True AndAlso 
     c.Active = True  
Select c