C# 显示无法创建“”类型的常量值。在此上下文中仅支持基元类型(“如Int32、String和Guid”)
我正在使用linq查询一些表,以根据某些条件获得员工列表。作为 这里的类EmpJobPosition来自模型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)
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();