简体   繁体   English

使用多个字段加入linq查询

[英]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 我正在尝试使用linq中的多个字段进行联接的选择查询,但是编译器在联接时给我以下错误: -join子句中表达式之一的类型不正确

(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. 有人可以对此发表看法吗,这句话有什么问题,谢谢。

Join keys have to have same properties, but in your case left key has Id,TeamId properties, and right key has RoleId,TeamId properties. 连接键必须具有相同的属性,但是在您的情况下,左键具有Id,TeamId属性,而右键具有RoleId,TeamId属性。 So you have to rename either Id to RoleId , or do the opposite. 因此,您必须将Id重命名为RoleId ,或者相反。

(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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM