在IQueryable查询中减去DateTimes

时间:2013-09-13 04:25:04

标签: c# .net linq iqueryable

你好我试图在我的查询中减去两个DateTimes并将defference与timeInterval进行比较,但我得到了exeption:

 <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);    

如何在代码中减去日期?

1 个答案:

答案 0 :(得分:0)

使用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