2014-04-25 22 views
0

我有一個視圖上的網格的MVC應用程序。用戶可以使用不同的信息過濾網格上的數據。一種方法是在日期範圍內使用兩個日期選擇器(最小/最大)。我試圖在業務邏輯中找到所有匹配的數據集。但由於某些原因,日期範圍始終返回空集。我知道我沒有把它編碼正確,但不知道要改變什麼。這是代碼 -實體框架 - 日期範圍

filteredbyCustCriteria = _unitOfWork.CustomerRepository.Get.Where 
(w => (reportSearch.FullName != null ? (w.FirstName + " " + w.LastName).Contains(reportSearch.FullName.Trim()) : true) 
&& (reportSearch.MinPaidDate != null ? EntityFunctions.TruncateTime(w.Orders.FirstOrDefault().OrderPayments.FirstOrDefault().PaymentDate) >= reportSearch.MinPaidDate : true) 
&& (reportSearch.MaxPaidDate != null ? EntityFunctions.TruncateTime(w.Orders.FirstOrDefault().OrderPayments.FirstOrDefault().PaymentDate) <= reportSearch.MaxPaidDate : true)); 

它的作品找到全名。

回答

2

在使用可爲空DateTime時,我發現在某些情況下我必須使用.Value。試試這個:

>= reportSearch.MinPaidDate.Value 
<= reportSearch.MaxPaidDate.Value 
+0

感謝您的反饋,但它仍然沒有返回 – Craig

+0

你有成形的SQL輸出,以確保它是有道理的任何記錄?順便說一句,我會寫更多像這樣的LINQ'(reportSearch.MinPaidDate == null || EntityFunctions.TruncateTime(w.Orders.FirstOrDefault()。OrderPayments.FirstOrDefault()。PaymentDate)> = reportSearch.MinPaidDate.Value)' –