Reputation: 123
I am trying to join for multiple tables with multiple conditions but for 1 of the joins I am getting ERROR
The type of one of the expressions in the join clause is incorrect. Type inference failed in the call to 'Join'.
from aq in auditUnitQuestions
join wt in questionWt on aq.AuditQuestionWtID equals wt.AuditQuestionWtID
join qt in auditQuestions on wt.AuditQuestionID equals qt.AuditQuestionID
join ac in AuditComponents on qt.ComponentID equals ac.ComponentID
join kra in AuditKRAs on new { ac.ComponentID, qt.KRAID } equals new { kra.ComponentID, kra.KRAID }
//below I am getting error (The type of one of the expressions in the join clause
//is incorrect. Type inference failed in the call to 'Join'.
join prm in auditParameters on new { kra.KRAID, qt.AuditParametersID } equals new { prm.AuditKRAID, prm.AuditingParametersID }
where aq.Unitcode == calendar.UnitCode
&& wt.AuditTypeID == auditType
&& qt.Isactive == "Y"
Upvotes: 1
Views: 82
Reputation: 4030
Your equality condition of your join cannot have anonymous types, you have to name the parameters:
join prm in auditParameters on new
{
kraID = kra.KRAID, auditParameterID = qt.AuditParametersID
}
equals new
{
kraID = prm.AuditKRAID, auditParameterID = prm.AuditingParametersID
}
Also, the types of the parameters must be equal. kra.KRAID
must have the same type as prm.AuditKRAID
.
Upvotes: 0
Reputation: 1500815
The problem is that you're joining over two anonymous types, but those types aren't compatible - the property names are different. You've got to have a single key type, so both sides of the equals
must be of the same type, basically.
Instead of this:
new { kra.KRAID, qt.AuditParametersID }
equals new { prm.AuditKRAID, prm.AuditingParametersID }
You should have something like:
new { kra.KRAID, qt.AuditParametersID }
equals new { KRAID = prm.AuditKRAID, AuditParametersID = prm.AuditingParametersID }
Or you could just explicitly specify the same names for both anonymous types:
new { x = kra.KRAID, y = qt.AuditParametersID }
equals new { x = prm.AuditKRAID, y = prm.AuditingParametersID }
Of course, the type of kra.KRAID
must be the same as the type of prm.AuditKRAID
, and likewise the type of qt.AuditParametersID
must be the same as the type of prm.AuditingParametersID
or the anonymous types still won't match.
Upvotes: 1
Reputation: 3955
I think the problem is that the equality condition must be named or have the same name, this is why you have to replace the problematic row with this:
join prm in auditParameters on
new { KRAID = kra.KRAID, AuditID = qt.AuditParametersID }
equals
new { KRAID = prm.AuditKRAID, AuditID = prm.AuditingParametersID }
Upvotes: 1