【问题标题】:Only primitive types or enumeration types are supported in this context- linq join此上下文中仅支持原始类型或枚举类型- linq join
【发布时间】:2018-08-27 15:36:00
【问题描述】:

我在尝试加入时收到此错误

var users = _users.Get();
var userApprovals =
(from approval in _entities.ApprovalEntities
join userDetail in users on approval.UserKey equals userDetail.UserId
 where approval.EmployeeUid == employeeUid
 select new UserApproval
{
Id = approval.Id,
EmployeeUid = approval.EmployeeUid,
UserKey = approval.UserKey,
UserId = approval.UserId,
UserName = userDetail.FirstName + " " + userDetail.LastName
}).ToList();

错误 此上下文仅支持原始类型或枚举类型

谢谢

【问题讨论】:

    标签: linq linq-to-entities


    【解决方案1】:

    固定, var userApprovals =

    (from approval in _entities.ApprovalEntities.ToList()
    join userDetail in users on approval.UserKey equals userDetail.UserId
     where approval.EmployeeUid == employeeUid
     select new UserApproval
    {
    Id = approval.Id,
    EmployeeUid = approval.EmployeeUid,
    UserKey = approval.UserKey,
    UserId = approval.UserId,
    UserName = userDetail.FirstName + " " + userDetail.LastName
    }).ToList();
    

    【讨论】:

    • 所以你的修复从 ApprovalEntities 表中获取所有记录。这就是你想要的吗?
    【解决方案2】:

    就我而言,我的问题是使用 IEnumerable 而不使用 toList() 语句。

    看,这段代码显示“error Only primitive types or enumeration types are supported in this context”错误:

    var query = db.TemplatesDocs.Where(x => x.Id_Template == idTmpl)
            .Join(Utils.DocumentTypes, x => x.Id_Type, y => y.Id, (x, y) => new { tmpDoc = x, type = y } )
            .ToList();
    

    看,这段代码修复了错误:

    var query = db.TemplatesDocs.Where(x => x.Id_Template == idTmpl).ToList()
            .Join(Utils.DocumentTypes, x => x.Id_Type, y => y.Id, (x, y) => new { tmpDoc = x, type = y } )
            .ToList();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多