【发布时间】:2011-07-08 09:24:44
【问题描述】:
这无法编译:
void Foo()
{
using (var db = new BarDataContext(ConnectionString))
{
// baz is type 'bool'
// bazNullable is type 'System.Nullable<bool>'
var list = db.Bars.Where(p => p.baz && p.bazNullable); // Compiler:
// Cannot apply operator '&&' to operands of type
// 'System.Nullable<bool> and 'bool'
}
}
我真的必须通过两次运行来实现这一点,我首先使用 as 条件,然后使用可以为空的条件运行该列表,还是有更好的干净流畅的最佳实践方法来做到这一点?
【问题讨论】:
标签: c# linq-to-sql lambda expression nullable