Click here to Skip to main content
15,922,015 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have following code in linq C# where i wanted to get only single employee data.

Employee ObjEmployee = new Employee();
ObjEmployee.GetAllEmployee().Where(emp => emp.EmployeeCode == txtempcode.Text);

where GetAllEmployee() returns List, it is working. but the linq expression throwing following error

expression cannot contain lambda expressions.
Posted
Comments
Maciej Los 22-May-14 5:01am    
GetAllEmployee() returns List, it is working" - Are you sure?
It looks like ObjEmployee stores single employee data, not a list of employees.
Provide class declaration and implementation - use "Improve question" widget.
Maciej Los 22-May-14 5:10am    
Do not repost!
http://www.codeproject.com/Questions/776490/expression-cannot-contain-query-expressions

1 solution

To search for a single employee data you should change you code like in the next example:
C#
Employee ObjEmployee = dataContext.Employees.FirstOrDefault(emp => emp.EmployeeCode == txtempcode.Text);


Where dataContext is your data context object, an object of type of your "Data Context Class" derived from ObjectContext.
 
Share this answer
 
v3
Comments
[no name] 22-May-14 5:06am    
good solution

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