[英]Showing Unable to create a constant value of type ''. Only primitive types ('such as Int32, String, and Guid') are supported in this context
I am quering the some tables to get the list of employees based on some conditions using the linq. 我正在查询一些表以使用linq根据某些条件获取雇员列表。 as
如
Here class " EmpJobPosition " is from Model. 这里的“ EmpJobPosition”类来自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();
But Here while join with empJobPositionList it is showig error like 但是在这里,当与empJobPositionList一起加入时,它是showig错误,例如
{"Unable to create a constant value of type 'Etisbew.eOffice.EFModel.EntityModel.EmpJobPosition'. Only primitive types ('such as Int32, String, and Guid') are supported in this context."}
{“无法创建类型为'Etisbew.eOffice.EFModel.EntityModel.EmpJobPosition'的常量值。在此上下文中仅支持基本类型(例如Int32,String和Guid'。”)
What is the problem here. 这里有什么问题。
You could do something like that (don't try to join an IQueryable on an List) 您可以执行类似的操作(不要尝试在列表上加入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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.