Linq Query无法跳过具有空日期的行

时间:2012-03-08 19:54:22

标签: c# linq casting

我有这个linq查询需要跳过具有空日期的行。但是当遇到空日期时,我会收到一个转换错误。任何和所有的帮助表示赞赏。

var p = (from c in REPORT.GET_PERMITS_BY_ISSUED_DATE
      where (
      ((DateTime?)c.Submittals_Approval != null)
      && ((DateTime?)c.Submittals_Approval >= FromDate) 
      && ((DateTime?)c.Submittals_Approval <= ToDate)
       )
       select c.Permit_Bond_Amount).Sum();

1 个答案:

答案 0 :(得分:0)

我用它来工作:

var p = (from c in REPORT.GET_PERMITS_BY_ISSUED_DATE 
where ( (c.Field<DateTime?>("Submittals_Approval") != null) &&
(c.Field<DateTime?>("Submittals_Approval") >= FromDate) && 
(c.Field<DateTime?>("Submittals_Approval") <= ToDate) )
select c.Permit_Bond_Amount).Sum();