C# 实体框架-日期范围

C# 实体框架-日期范围,c#,linq,entity-framework,linq-to-sql,C#,Linq,Entity Framework,Linq To Sql,我有一个MVC应用程序,视图上有一个网格。允许用户使用不同的信息过滤网格上的数据。一种方法是对日期范围(最小/最大)使用两个日期选择器。我试图在业务逻辑中找到所有匹配的数据集。但是由于某些原因,日期范围总是返回一个空集。我知道我没有正确的编码,但不确定要更改什么。这是密码- filteredbyCustCriteria = _unitOfWork.CustomerRepository.Get.Where (w => (reportSearch.FullName != null ? (w.F

我有一个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));
FilteredByCustomCriteria=\u unitOfWork.CustomerRepository.Get.Where
(w=>(reportSearch.FullName!=null?(w.FirstName+“”+w.LastName)。包含(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)使用nullable
DateTime
时,我发现在某些情况下必须使用
.Value
。请尝试以下操作:

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

感谢您的反馈,尽管它仍然没有返回任何记录您分析了SQL输出以确保其有意义吗?顺便说一句,我会更像这样编写LINQ
(reportSearch.MinPaidDate==null | | EntityFunctions.TruncateTime(w.Orders.FirstOrDefault().OrderPayments.FirstOrDefault().PaymentDate)>=reportSearch.MinPaidDate.Value)