簡體   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

我正在查詢一些表以使用linq根據某些條件獲取雇員列表。

這里的“ 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();

但是在這里,當與empJobPositionList一起加入時,它是showig錯誤,例如

{“無法創建類型為'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();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM