简体   繁体   English

显示无法创建类型“”的常量值。 在这种情况下,仅支持基本类型(例如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

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.

相关问题 无法创建类型为“结算类型”的常量值。 在这种情况下,仅支持基本类型(例如Int32,String和Guid) - Unable to create a constant value of type 'Closure type'. Only primitive types ('such as Int32, String, and Guid') are supported in this context EF-Code First:无法创建类型&#39;&#39;的常量值。 在此上下文中仅支持原始类型(例如Int32,String和Guid&#39;) - EF-Code First: Unable to create a constant value of type ''. Only primitive types ('such as Int32, String, and Guid') are supported in this context 此上下文仅支持原始类型(“例如 Int32、String 和 Guid”) - Only primitive types ('such as Int32, String, and Guid') are supported in this context Linq,array.Contains()生成异常:在此上下文中仅支持基本类型(例如Int32,String和Guid&#39;) - Linq, array.Contains() generating exception: Only primitive types ('such as Int32, String, and Guid') are supported in this context 表达式-无法创建类型为&#39;System.Collections.Generic.List`1&#39;的常量值。 仅原始类型(例如Int32,String和Gu - Expression - Unable to create a constant value of type 'System.Collections.Generic.List`1'. Only primitive types ('such as Int32, String, and Gu EF错误无法创建类型为“匿名类型”的常量值。 在此上下文中仅支持原始类型或枚举类型 - EF error Unable to create a constant value of type 'Anonymous type'. Only primitive types or enumeration types are supported in this context 无法创建“匿名类型”类型的常量值。 在此上下文中仅支持基元类型或枚举类型 - Unable to create a constant value of type 'Anonymous type'. Only primitive types or enumeration types are supported in this context EntityFramework无法创建“匿名类型”类型的常量值。 在此上下文中仅支持基元类型或枚举类型 - EntityFramework Unable to create a constant value of type 'Anonymous type'. Only primitive types or enumeration types are supported in this context UOW模式-无法创建类型的常量值在此上下文中仅支持基本类型或枚举类型 - UOW pattern - Unable to create a constant value of type Only primitive types or enumeration types are supported in this context C# - Linq:无法创建类型的常量值在此上下文中仅支持基本类型或枚举类型。 - C# - Linq : Unable to create a constant value of type Only primitive types or enumeration types are supported in this context.
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM