【发布时间】:2010-09-30 14:22:43
【问题描述】:
当使用 linq 查询集合时,它总是返回 null
Collection<JCTransLabour> oJCTransLabours = null;
oJCTransLabour = HttpContext.Current.Session["CurrentLabourTransactions"] as
Collection<JCTransLabour>;
// at this point the collection oJCTransLabours contains 3500 records
var oCurrentLabourTrans = from clt in oJCTransLabours
where clt.TransactionDate.Date != DateTime.Now.Date
select clt;
// at this point the collection oJCTransLabour = null
// I have tried to search on different fields
return oCurrentLabourTrans;
一定是我做错了什么。任何帮助将不胜感激。
【问题讨论】:
-
第一步之后,是变量oJCTransLabour真的不为null,还是HttpContext.Current.Session["CurrentLabourTransactions"]不为null,因为c#中的'as Collection'运算符返回null如果类型不匹配,则与 (Collection) 变量相反,它会给出异常。
-
附带说明,请注意
DateTime.Now。查看DateTime.UtcNow。
标签: c# linq collections