Nhibernate LINQ DateTime.AddDay 异常 NotSupportedException

.Net技术 码拜 8年前 (2015-12-20) 2380次浏览 0个评论

在C# Nhibernate开发中使用了linq 查询,我需要对比2个DateTime类型的时间,其中用到DateTime.AddDay(),代码如下:

<code>var patients = from c in session.Query<Patient>() where c.DateAdded.AddDays(1) < c.AdmitDate select c;</code>

但是当程序运行时发生如下异常: System.NotSupportedException {“System.DateTime AddDays(Double)”}

at NHibernate.Linq.Visitors.HqlGeneratorExpressionTreeVisitor.VisitMethodCallExpression(MethodCallExpression expression)

使用foreach遍历,将时间对比作为内部条件时运行正常,例如:

foreach (var model in patients)
{
if(DateAdded.AddDays(1) > c.AdmitDate)continue;//类似的如:AddMinutes
}

最终的方法是先转换为ToList(),然后再用linq。

var pats=session.Query<Patient>().ToList();


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明Nhibernate LINQ DateTime.AddDay 异常 NotSupportedException
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!