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

在我的 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 };

相关文章

目录简介使用JS互操作使用ClipLazor库创建项目使用方法简单测...
目录简介快速入门安装 NuGet 包实体类User数据库类DbFactory...
本文实现一个简单的配置类,原理比较简单,适用于一些小型项...
C#中Description特性主要用于枚举和属性,方法比较简单,记录...
[TOC] # 原理简介 本文参考[C#/WPF/WinForm/程序实现软件开机...
目录简介获取 HTML 文档解析 HTML 文档测试补充:使用 CSS 选...