Reputation: 786
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
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