2014-01-29 63 views
0

我在查詢某些表以根據使用linq的某些條件獲取僱員列表。 as顯示無法創建類型爲''的常量值。只有原始類型('如Int32,字符串和Guid')在此上下文中受支持

這裏的類「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它就像

{「無法創建類型‘Etisbew.eOffice.EFModel.EntityModel.EmpJobPosition’的恆定值。只有原始類型showig錯誤( '如Int32,String和Guid')在這種情況下受支持。「}

這裏有什麼問題。

回答

1

你可以做這樣的事情(不要試圖加入一個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(); 
+0

它的工作太好了,謝謝 –

相關問題