2014-01-13 117 views
0

我想在linq中的連接謂詞中使用兩個字段。如何添加其他字段?在linq連接謂詞中使用「和」

var Result = from Period in context.PeriodCosts 
       join Name in context.Name on Period.ID equals Name.PeriodID 
       /*"Problem is here ==> */and 
       Period.CCID equals Name.CCID" 
       select Name; 

回答

5

使用匿名類型:

var Result = from Period in context.PeriodCosts 
      join Name in context.Name 
       on new { ID = Period.ID, CCID = Period.CCID } 
       equals new { ID = Name.PeriodID, CCID = Name.CCID } 
      Period.CCID equals Name.CCID" 
      select Name; 
1

嘗試以下

var Result = from Period in context.PeriodCosts 
      join Name in context.Name on 
      new{Period.ID, Period.CCID} equals new { Name.PeriodID, Name.CCID}    
      select Name;