在此context-linq join中仅支持原始类型或枚举类型

时间:2015-03-03 18:44:31

标签: linq linq-to-entities

我尝试加入时收到此错误

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();

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

由于

2 个答案:

答案 0 :(得分:0)

固定, 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();

答案 1 :(得分:0)

在我的情况下,我的问题是使用IEnumerable而不使用toList()语句。

看,这段代码显示“在此上下文中仅支持基本类型或枚举类型”错误:

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();