我有一个iQueryable,我需要知道它是否为null或没有值.
IQueryable<people> L = (from p in people
where p.lastname.Contains("y")
select p);
if (L != null && L.Count() > 0) {
return "Something";
} else {
return "NOTHING";
}
Run Code Online (Sandbox Code Playgroud)
好吧,如果你使用L.Count()它将使用更多的资源.有没有更好的办法?不使用的东西L.Count()
建议您使用.Any().
IQueryable<people> L = (from p in people
where p.lastname.Contains("y")
select p);
if (L.Any()) {
return "Something";
} else {
return "NOTHING";
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3716 次 |
| 最近记录: |