我想在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;
答案 0 :(得分: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 :(得分: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;