2

您好,我正在尝试在查询中减去两个 DateTime,并将差异与 timeInterval 进行比较,但我得到了例外:

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

如何在代码中减去日期?

4

1 回答 1

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

于 2013-09-13T04:30:04.807 回答