Learner
Learner

Reputation: 786

Join in linq query using multiple fields

I am trying following select query with join using multiple fields in linq, but compiler is giving me the error on join that :- the type of one of expression in join clause is incorrect

(from allTeamRoles in GetAllTeamRoles()
                    join includedRoles in _jobManagerClient.GetAllJobRoles().Where(x => x.JobId == jobId)
                    on new { allTeamRoles.Id, allTeamRoles.TeamId } equals new { includedRoles.RoleId, includedRoles.TeamId }
                    select allTeamRoles).ToList();

Can somebody throw a light on this, what is wrong with this statement, Thanks.

Upvotes: 1

Views: 59

Answers (1)

Ulugbek Umirov
Ulugbek Umirov

Reputation: 12797

Join keys have to have same properties, but in your case left key has Id,TeamId properties, and right key has RoleId,TeamId properties. So you have to rename either Id to RoleId, or do the opposite.

(from allTeamRoles in GetAllTeamRoles()
 join includedRoles in _jobManagerClient.GetAllJobRoles().Where(x => x.JobId == jobId)
 on new { allTeamRoles.Id, allTeamRoles.TeamId } equals new { Id = includedRoles.RoleId, includedRoles.TeamId }
 select allTeamRoles).ToList();

Upvotes: 4

Related Questions