Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 显示无法创建“”类型的常量值。在此上下文中仅支持基元类型(“如Int32、String和Guid”)_C#_Linq - Fatal编程技术网

C# 显示无法创建“”类型的常量值。在此上下文中仅支持基元类型(“如Int32、String和Guid”)

C# 显示无法创建“”类型的常量值。在此上下文中仅支持基元类型(“如Int32、String和Guid”),c#,linq,C#,Linq,我正在使用linq查询一些表,以根据某些条件获得员工列表。作为 这里的类EmpJobPosition来自模型 List<int> empjList=ObjToList(employeeJobPositionIds); List<EmpJobPosition> empJobPositionList = (from i in ctx.EmpJobPositions where empjList.Contains(i.EmpJobPositionId)

我正在使用linq查询一些表,以根据某些条件获得员工列表。作为

这里的类EmpJobPosition来自模型

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时,它显示的错误如下

{无法创建“Etisbew.eOffice.EFModel.EntityModel.EmpJobPosition”类型的常量值。此上下文中仅支持“Int32、String和Guid”等基本类型。}


这里有什么问题。

你可以做类似的事情,但不要尝试加入列表中的IQueryable

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