gpt4 book ai didi

c# - linq中的加入子句

转载 作者:太空宇宙 更新时间:2023-11-03 15:32:58 25 4
gpt4 key购买 nike

我创建了三个表的名称:emps、emp_project、emp_location

现在我想从每个表中选择一列,但是当我执行连接查询时出现这个错误:

The type of one of the expressions in the join clause is incorrect. Type inference failed in the call to 'GroupJoin'.

我正在执行的查询是:

from e in Emp_info
from p in Emp_projects
join l in Emp_locations
on new { e.User_id , p.Project_id } equals new { l.User_id, l.Project_id } into detail
from l in detail
select new
{
e.Middlename,
p.Project_name,
l.Location
};
query.Dump("Join query");

不知道是哪个子句导致了错误!

最佳答案

我的猜测是,它试图比较的两个匿名类型不相同(还要确保属性是相同的数据类型)。

改变

on new { e.User_id , p.Project_id  } equals new { l.User_id, l.Project_id  } into detail

 on new { UserId = e.User_id, ProjectId = p.Project_id  } equals 
new { UserId = l.User_id, ProjectId = l.Project_id } into detail

关于c# - linq中的加入子句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33119447/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com