Click here to Skip to main content
15,943,061 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
public List<Customers> GetEmployeebyID(Customers cs)
      {
          CompanyDataContext db = new CompanyDataContext();
          employee emp = new employee();
          List<Customers> lst = new List<Customers>();
          lst = db.employees.Where(p =>p.empid=cs.employeeid).Select(p => new { p.departmentid, p.empname, p.Isworking, p.jobid, p.locationid });
      }

i am getting error cannot covert implicitly type to bool at where(p=>p.empid=cs.employeeid)

please help me
thank you
Posted
Updated 18-Feb-12 20:53pm
v2

Try this Code
C#
public List<customers> GetEmployeebyID(Customers cs)
{
    CompanyDataContext db = new CompanyDataContext();
    employee emp = new employee();
    List<customers> lst = new List<customers>();
    lst = db.employees.Where(p =>p.empid==cs.employeeid).Select(p => new { p.departmentid, p.empname, p.Isworking, p.jobid, p.locationid });
}


--vote/accept solution
--if this will help you
--thanks
 
Share this answer
 
v4
Comments
Sander Rossel 19-Feb-12 3:19am    
I might be missing something, but how is this code different from the op's?
The probleem seems to be that your cs variable is a collection of customers. So when you have this little lambda expressions p =>p.empid=cs.employeeid it is not clear which employeeid should be taken. Is it the employeeid of the first customer, of the last customer or somewhere in between? Try passing in a single customer or specify which element from the list you want.
Alternatively, if cs is already a single customer (in which case you should change your class name of Customers to Customer) it might be that employeeid is nullable[^]. Nullable types[^] have a Value Property[^] which you should use if you want to compare it's value to another value. You might need to use the HasValue Property[^] first to check if it actually has a value so that no Exception occurs.
Hope it helps!
 
Share this answer
 
Comments
sreekanth12 19-Feb-12 8:13am    
i am totally confused i added this code. its working
thank you.
csa = db.employees.Where(p => p.departmentid == cs.departmentid).Select(p => new Customers { employeeid = p.empid, jobid = p.jobid }).ToList();
return csa;
Sander Rossel 19-Feb-12 8:50am    
No problem I guess... Although I don't really see how my suggestions could've helped you. It seems you've just been querying the wrong properties (which can happen!) :)

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