linq错误lambda表达式 [英] linq error lambda expression
本文介绍了linq错误lambda表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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 });
}
我遇到错误,无法隐式键入where(p=>p.empid=cs.employeeid)
的布尔值
请帮助我
谢谢
i am getting error cannot covert implicitly type to bool at where(p=>p.empid=cs.employeeid)
please help me
thank you
推荐答案
尝试此代码
Try this Code
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 });
}
-投票/接受解决方案
-如果这对您有帮助
--thanks
--vote/accept solution
--if this will help you
--thanks
问题似乎是您的cs
变量是客户集合.因此,当您有这么小的lambda表达式p =>p.empid=cs.employeeid
时,不清楚应该使用哪个employeeid
.是第一个客户,最后一个客户或介于两者之间的employeeid
吗?尝试传入单个客户或从列表中指定所需的元素.
或者,如果cs
已经是一个客户(在这种情况下,您应该将类的名称从Customers
更改为Customer
),则可能是employeeid
是 ^ ]. 可空类型 [值属性 [ ^ ],如果要将其值与另一个值进行比较,应使用该值.您可能需要使用 HasValue属性 [
The probleem seems to be that yourcs
variable is a collection of customers. So when you have this little lambda expressionsp =>p.empid=cs.employeeid
it is not clear whichemployeeid
should be taken. Is it theemployeeid
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, ifcs
is already a single customer (in which case you should change your class name ofCustomers
toCustomer
) it might be thatemployeeid
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 noException
occurs.
Hope it helps!
这篇关于linq错误lambda表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文