Using lambda expressions, how do you translate this query?
select * from employee where emp_id=1 and dep_id in (1,2,3,4).
I am trying this expression but this results in exceptions:
public IEnumrable<employees> getemployee(int emp开发者_如何学Python,list<int> dep )
{
_employeeService.GetAll(e=>(e.emp_id=emp||emp==null) && (e.dep_id.where(dep.contains(e.dep_id))|| dep.count==0 )
}
Any suggestion for translating these queries to these lambda expressions? wahts wrong in these function?
I don't mean to sound patronizing, but I'd suggest you pick up a beginner's C# book before going further. You've made errors in basic syntax such as operator precedence and equality comparison. Also, remember that primitive data types cannot be checked for null, unless they're explicitly specified as nullable. In your case emp would be of type int?,not int. Meanwhile, try
_employeeService.Where(e=>(e.emp_id==emp) && (dep == null || dep.contains(e.dep_id)) );
精彩评论