下面的代码应该从具有table
和数据比status = 1
年长的90 days
返回结果。在table
有很多数据的拥有modified date
更than90 days
。
但是,此代码返回0的结果。该datetime
差异抛出错误,以便使用DbFunctions
替代,因为EF我现在用的就是EF6。
IEnumerable<IncentiveClaim> claims = repository.Table
.Where(c => c.Status == 1
&& DbFunctions.DiffDays(DateTime.Now, c.ModifiedDate) >= 90)
.AsEnumerable();
该方法具有参数作为DbFunctions.DiffDays(smallestDateTime, LargestDateTime)
。因此,ModifiedDate
应该是第一个参数,DateTime.Now
应该是第二个参数。然后,你必须调用.Value
的方法来获取no. of days
。
修改代码如下:
IEnumerable<IncentiveClaim> claims = repository.Table
.Where(c => c.Status == 1
&& DbFunctions.DiffDays(c.ModifiedDate, DateTime.Now).Value >=
90)
.ToList();