问题描述
我将 Nhibernate 3.3.3.4001 与 SybaseSQLAnywhere12Dialect 一起使用,并尝试在 sum linq 函数中使用简单的计算.
我想使用 Linq 而不是 HQL 来实现这一点,并且很乐意使用默认的 linq to hql 生成器来扩展 Nhibernate.
使用以下 Linq 查询会引发异常
<块引用>System.NotSupportedException:此 SelectClauseVisitor 不支持表达式类型"NhSumExpression"
Linq 查询
var query = (from c in session.Query<Entity>() select c.FieldValue / 100M).Sum()
预期的 SQL 语句
SELECT SUM(FieldValue / 100.0) FROM TableName
如果在没有 Sum() 函数的情况下运行相同的查询,它会正确执行计算,因此我很困惑为什么 Sum() 不起作用.
推荐答案
在 Linq 组函数(Max、Min、Sum)函数中使用常量时存在一个未解决的问题.如果使用其他字段,它将正常工作.
在 NHibernate 3.3.3 中发现错误
https://nhibernate.jira.com/browse/NH-3376
问题描述
I am using Nhibernate 3.3.3.4001 with SybaseSQLAnywhere12Dialect and trying to use a simple calculation within a sum linq function.
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.
Using the following Linq query raises the exception
System.NotSupportedException: Expression type 'NhSumExpression' is not supported by this SelectClauseVisitor
Linq Query
var query = (from c in session.Query<Entity>() select c.FieldValue / 100M).Sum()
Expected SQL Statement
SELECT SUM(FieldValue / 100.0) FROM TableName
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.
推荐答案
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.
Found bug within NHibernate 3.3.3
https://nhibernate.jira.com/browse/NH-3376