Click here to Skip to main content
15,896,912 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hi,

I am querying the some tables to get the list of employees based on
some conditions using the linq. as

Here class " EmpJobPosition" is from Model.



C#
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()
                            where (resg == null || resg.HasLeft == false) &&  
                             select new EmployeesViewModel()).ToList();




But Here while join with empJobPositionList it is showig error like

{"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."}

What is the problem here.


Thank you.
Posted
Updated 29-Jan-14 5:38am
v2
Comments
Sergey Alexandrovich Kryukov 29-Jan-14 15:01pm    
Just do what you are required to, according to this message. Recompose your query to use only the primitive types, strings and GUID, which can be members of your JobPosition type.
—SA
V G S Naidu A 29-Jan-14 23:48pm    
HERE in the above query, if we use directly "ctx.EmpJobPositions " instead of filtered "empJobPositionList" which is of type "EmpJobPosition" it's working fine, but if you are filtering the "ctx.EmpJobPositions" into "empJobPositionList" and do join with other tables it's showing above error. why?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900