c# - 在 IQueryable 查询中减去 DateTimes

标签 c# .net linq iqueryable

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

相关文章:

c# - 过滤具有特定属性的对象列表

.net - 在 Windows 7 for XP/Vista 上开发 .NET 应用程序

c# - 调用另一个 WCF 服务的 WCF 服务很慢

c# - PLINQ 查询给出溢出异常

c# - 如果值为字符串类型则按片段搜索,但如果值为 int 则按整个搜索

c# - 从另一个列表中删除一个对象列表

c# - WorkingThread 未启动

c# - 调用 SignedCMS.Decode 花费的时间太长

c# - c# 中的预期类、委托(delegate)、枚举、接口(interface)或结构

.net - 哪些报告框架或报告控件可以与 Mono.net 一起使用?请列出它们的名称?