我有一个List lstStudents = GetStudents()//这个方法可以返回null。 现在,我想在我的数据库表的学生运行此查询,检查LINQ to SQL查询中的List是否为空?
var result = (from c in student
where lstStudents.Contains(c.name)
select c);
如何检查是否lstStudents是不是查询里面空。
注:我知道我可以在查询运行之前检查它,但由于某些其他原因我无法做到这一点。如果我尝试(lstStudents!= null)在查询内部出错。
无法比较 'System.Collections.Generic.List`1 [[System.String,mscorlib程序, 版本= 4.0.0.0,文化=中性公钥= b77a5c561934e089]]' 类型的元素。 仅支持原始类型,枚举类型和实体类型 。
任何帮助表示赞赏。
'lstStudents'是LINQ查询外,你更好的声明前检查。并处理如果'lstStudents'为空 – Bhaarat
当'lstStudents'为空时你想得到什么?请在问题中描述它。 –
“注意:我知道在查询运行前我可以检查它,但由于某些其他原因,我无法做到这一点。” - 请详细说明其他原因,因为这正是你应该做的。如果有什么阻止,也许这可以解决。 – hvd