If statement 可选,在Linq到SQL查询中的何处

If statement 可选,在Linq到SQL查询中的何处,if-statement,linq-to-sql,where,If Statement,Linq To Sql,Where,仅当DateTime时,我才尝试筛选表?start不是null,但是我得到了一个异常,我触摸了null对象的.Value。实现这一目标的正确方法是什么 .Where(e => start.HasValue ? e.Timestamp >= start.Value : true) 对不起,伙计们,我自己找到了答案。这个很好用: .Where(e => !start.HasValue || e.Timestamp >= start) 我在SQL事件探查器中查看了—当sta

仅当
DateTime时,我才尝试筛选表?start
不是null,但是我得到了一个异常,我触摸了null对象的
.Value
。实现这一目标的正确方法是什么

.Where(e => start.HasValue ? e.Timestamp >= start.Value : true)

对不起,伙计们,我自己找到了答案。这个很好用:

.Where(e => !start.HasValue || e.Timestamp >= start)
我在SQL事件探查器中查看了—当
start
为空时,Linq to SQL完全删除
Where