你好,我想在我的查询中减去两个 DateTimes 并将差异与 timeInterval 进行比较,但我得到了异常(exception):
<Message>An error has occurred.</Message>
<ExceptionMessage>System.TimeSpan Subtract(System.DateTime)</ExceptionMessage>
<ExceptionType>System.NotSupportedException</ExceptionType>
C#代码:
producerRelations = producerRelationRepository.Query().Fetch(c => c.Order).
Where(c => c.Order.CreatedBy == login).
Where(c=>currentDate.Subtract(c.RouteUnit.DtStart.Value).TotalMinutes<timeInterval);
如何在我的代码中减去日期?
最佳答案
使用AsEnumerable
producerRelations = producerRelationRepository.Query().Fetch(c => c.Order).
Where(c => c.Order.CreatedBy == login).AsEnumerable().
Where(c=>currentDate.Subtract(c.RouteUnit.DtStart.Value).TotalMinutes<timeInterval);
或者你需要使用EntityFunctions
关于c# - 在 IQueryable 查询中减去 DateTimes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18778292/