I have a MVC application with a grid on the view. The user is allowed to filter the data on the grid using different information. One way is to use two datepickers for date range (min/max). I attempting to find all matching datasets in the business logic. But for some reason the date range always returns a empty set. I know I don't have it coded right, but not sure what to change. This is the code -

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));

It works find on the fullname.

有帮助吗?

解决方案

When working with nullable DateTime I find that I have to use .Value in certain cases. Try this:

>= reportSearch.MinPaidDate.Value
<= reportSearch.MaxPaidDate.Value
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top