我在前一天張貼了一些代碼的一部分,但這樣做導致了更多的混淆。這是我的代碼。當使用linq查詢一個集合時,它總是返回一個空值
if (HttpContext.Current.Session != null)
{
if (HttpContext.Current.Session[ "CurrentLabourTransactions" ] != null)
{
Collection<JCTransLabour> oJCTransLabours = null;
oJCTransLabours = (Collection<JCTransLabour>)HttpContext.Current.Session["CurrentLabourTransactions"];
if (Settings.ShowTodaysTransactionInApproval)
if (oJCTransLabours != null) return oJCTransLabours;
if (oJCTransLabours != null)
{
//oJCtransLabour contains alot of record
var oCurrentLabourTrans = (from clt in oJCTransLabours
where clt.TransactionDate.Date != DateTime.UtcNow
select clt);
//oCurrentLabourTrans is null.
return oCurrentLabourTrans as Collection<JCTransLabour>;
}
}
}
return null;
當進入最終的if語句時,會有許多具有不同日期的事務。它似乎儘管它總是返回空記錄。
在此先感謝您的幫助。
你的意思是,它總是返回* NULL *,或者它總是返回空行的集合? – 2010-10-04 16:02:19
是'oCurrentLabourTrans'null還是'oCurrentLabourTrans作爲集合'null? –
2010-10-04 16:02:59
[使用linq查詢集合時總是返回null]的可能重複(http://stackoverflow.com/questions/3831490/when-querying-a-collection-using-linq-it-always-returns-a- null) – Guffa 2010-10-04 16:03:51