显示无法创建类型“"的常量值.在这种情况下,仅支持基本类型(例如Int32,String和Guid) [英] Showing Unable to create a constant value of type ''. Only primitive types ('such as Int32, String, and Guid') are supported in this context

查看:75
本文介绍了显示无法创建类型“"的常量值.在这种情况下,仅支持基本类型(例如Int32,String和Guid)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在查询一些表以使用linq根据某些条件获取雇员列表.

I am quering the some tables to get the list of employees based on some conditions using the linq. as

这里的"EmpJobPosition"类来自Model.

Here class " EmpJobPosition " is from Model.

List<int> empjList=ObjToList(employeeJobPositionIds);

List<EmpJobPosition> empJobPositionList =
     (from i in ctx.EmpJobPositions
      where empjList.Contains(i.EmpJobPositionId)
      select i).ToList<EmpJobPosition>();

var query = (from emp in ctx.Employees
     join resg in ctx.Resignations on emp.EmployeeID equals resg.EmployeeID into resglist
     from resg in resglist.DefaultIfEmpty()
     join jpos in empJobPositionList
         on emp.EmployeeID equals jpos.EmployeeId into jposList
     from jpos in jposList.DefaultIfEmpty()
         (resg == null || resg.HasLeft == false) && emp.CompanyID == 1
     select new EmployeesViewModel()).ToList();

但是在这里,当与empJobPositionList一起加入时,它就像是showig错误

But Here while join with empJobPositionList it is showig error like

{无法创建类型为'Etisbew.eOffice.EFModel.EntityModel.EmpJobPosition'的常量值.在此上下文中仅支持基本类型(例如Int32,String和Guid'."}

这是什么问题.

推荐答案

您可以执行类似的操作(不要尝试在列表上加入IQueryable)

You could do something like that (don't try to join an IQueryable on an List)

var query = (
     from emp in ctx.Employees
     join resg in ctx.Resignations 
              on emp.EmployeeID equals resg.EmployeeID into resglist
     from leftresg in resglist.DefaultIfEmpty()

     //put the where clause on EmpJobPositions here
     join jpos in ctx.EmpJobPositions.Where(x => empjList.Contains(x.EmpJobPositionId))
              on emp.EmployeeID equals jpos.EmployeeId into jposList
     from leftjpos in jposList.DefaultIfEmpty()
         //don't understand this line, are you missing a where ?
         //(leftresg == null || leftresg.HasLeft == false) && emp.CompanyID == 1
     select new EmployeesViewModel()).ToList();

这篇关于显示无法创建类型“"的常量值.在这种情况下,仅支持基本类型(例如Int32,String和Guid)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆