c# - 无法连接表和 View - 调用 'join' 时类型推断失败

标签 c# mysql linq

我想将我的表列 EmployeeAccess.EmpNo 内部联接到我的 View 列 VIEW_HCM.EmpNo

public List<EmployeeAccess> EmployeeAccess4()
{
    var emp = from b in contxt.EmployeeAccesses
              join c in contxt.View_HCM on b.EmpNo equals c.EmpNo
              select new                     
              {
                  b.EmpNo,
                  c.EmailAddress
              };

}

我在加入时遇到错误:

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

最佳答案

您的字段之一是可为空。我并不是说您有空值,只是说类型可以为空

.Value 添加到 Nullable 字段以加入这些字段(我只是将其放在两个字段上,因为如果不查看您的 DDL,我不知道它是哪一个) :

 var emp = from b in contxt.EmployeeAccesses
              join c in contxt.View_HCM on b.EmpNo.Value equals c.EmpNo.Value
              select new                     
              {
                  b.EmpNo,
                  c.EmailAddress
              };

或者,如果您有权更改列,则将该列设置为 NOT NULL

关于c# - 无法连接表和 View - 调用 'join' 时类型推断失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22240830/

相关文章:

c# - 如何绕过 "Internal .NET Framework Data Provider error 1025."?

c# - 在Windows XP/Vista/Seven中获得GET Master音量(通常通过键盘滚轮增加音量)

mysql - 如何优化多连接的慢查询

恢复后的MySQL二进制日志

c# - 通过组合从列表 C# 中获取不同的项目

c# - 如何在组的开头和结尾处使用文本在 linq 中进行分组?

c# - JSON反序列化将负值转换为绝对值

javascript - 动态将从 Controller 返回的选择框值呈现为 json

php - SQL SELECT,显示多列中的多行

.net - 标准 SQL 查询比 Linq 2 SQL 快得多