Nhibernate Linq Sum与计算导致NotSupportedException [英] Nhibernate Linq Sum with calculation causes NotSupportedException

查看:60
本文介绍了Nhibernate Linq Sum与计算导致NotSupportedException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将Nhibernate 3.3.3.4001与SybaseSQLAnywhere12Dialect一起使用,并尝试在sum linq函数中使用简单的计算.

I am using Nhibernate 3.3.3.4001 with SybaseSQLAnywhere12Dialect and trying to use a simple calculation within a sum linq function.

我想使用Linq而不是HQL来实现这一目标,并且很乐意将具有默认linq的Nhibernate扩展到hql生成器.

I would like to use Linq rather than HQL to achieve this and would be happy to extend Nhibernate with a default linq to hql generator.

使用以下Linq查询会引发异常

Using the following Linq query raises the exception

System.NotSupportedException:此SelectClauseVisitor不支持表达式类型'NhSumExpression'

System.NotSupportedException: Expression type 'NhSumExpression' is not supported by this SelectClauseVisitor

Linq查询

var query = (from c in session.Query<Entity>()
            select c.FieldValue / 100M).Sum()

期望的SQL语句

SELECT SUM(FieldValue / 100.0) FROM TableName

如果在没有Sum()函数的情况下运行相同的查询,它将正确执行计算,因此很困惑为什么Sum()无法工作.

If the same query is run without the Sum() function it performs the calculation correctly, as such am confused why the Sum() wouldn't work.

推荐答案

在Linq组函数(最大,最小,总和)函数中使用常量时,存在一个未解决的问题.如果使用其他字段,它将正常工作.

There is an open issue when using constants within Linq group function (Max, Min, Sum) functions. If another field is used it will work correctly.

在NHibernate 3.3.3中发现了错误
https://nhibernate.jira.com/browse/NH-3376

Found bug within NHibernate 3.3.3
https://nhibernate.jira.com/browse/NH-3376

这篇关于Nhibernate Linq Sum与计算导致NotSupportedException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆