加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 类型推断在对可空和不可空的int进行“join”的调用中失败

发布时间:2020-12-15 03:45:25 所属栏目:百科 来源:网络整理
导读:在我的 Linq中,我试图使一个内部连接到一个可空字段.员工和部门有关系,部门可能有一个员工身份证件或可能有一个零.那么,如果我只想要满足内部连接的记录(对于null EmployeeID,没有结果),那么我的加入是什么: var result = from emp in employees join dept
在我的 Linq中,我试图使一个内部连接到一个可空字段.员工和部门有关系,部门可能有一个员工身份证件或可能有一个零.那么,如果我只想要满足内部连接的记录(对于null EmployeeID,没有结果),那么我的加入是什么:
var result = from emp in employees
             join dept in departments
             on new { Source = emp.EmployeeID }
             equals new { Source = dept.EmployeeID };

我有一个例外:

The type of one of the expressions in the join clause is incorrect.
Type Inference failed in a call to ‘join’.

谢谢

解决方法

如果你扭转你的加入并把一点点放在那里呢?
var result = from department in departments
             where department.EmployeeID != null
             join employee in employees
             on department.EmployeeID.Value equals employee.EmployeeID
             select new { employee,department };

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读