无法创建类型'的常量值。在此上下文中仅支持基元类型或枚举类型。 LINQ

时间:2015-08-12 17:38:45

标签: c# linq linq-to-entities linq-to-objects

我收到此异常,无法创建类型' XXX'的常量值。在此上下文中仅支持原始类型或枚举类型。

我试图在linq exression中进行子查询, 我使用2个数据源dbContext来获取所有数据和从服务返回的语言列表。

objData = (from s in db.Search
  let lan = langList
  //join l in db.Language on s.LanguageId equals l.Id
  join u in db.User on s.UserId equals u.Id
  where u.Id == (UserId == Guid.Empty ? u.Id : UserId)
        && s.isActive == true
        && s.SearchId == SearchId
  select new userModel.Search()
  {
      Language = (from l in lan
                  join sl in db.Search on l.Id equals sl.LanguageId
                  where (sl.Id == s.Id || sl.SearchId == s.SearchId) && sl.isActive == true
                  select new userModel.Language
                  {
                      Id = l.Id,
                      Name = l.Name,
                      Code = l.Code,
                      isActive = l.isActive,
                      CreatedAt = l.CreatedAt,
                      UpdatedAt = l.UpdatedAt,
                      DeletedAt = l.DeletedAt
                  }).ToList()
  }).ToList();

0 个答案:

没有答案