我想编写LINQ查询以始终返回空列表。我可以在SQL中执行以下操作:
SELECT * FROM EMPLOYEES WHERE 1=2
如何在LINQ中完成?
我的确切情况是
private IQueryable <EMPLOYEE> getEmployee()
{
IQueryable <EMPLOYEE> employees;
//code
if(condition)
{
return employees
}
else
{
//here I want to return a empty result.
}
}
没有必要打数据库。您可以使用以下内容:
private IQueryable <EMPLOYEE> getEmployee()
{
return Enumerable.Empty<EMPLOYEE>().AsQueryable();
}