gpt4 book ai didi

c# - 在 IQueryable 查询中减去 DateTimes

转载 作者:太空宇宙 更新时间:2023-11-03 16:07:33 24 4
gpt4 key购买 nike

你好,我想在我的查询中减去两个 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/

24 4 0