Nhibernate - 方言不支持 DbType.Double
当我尝试执行此查询时:
var q = session.QueryOver<Member>();
q.Select(Projections.Avg<Member>(x => x.AccountBalance));
var result = q.List();
我得到一个:
Dialect does not support DbType.Double
Parameter name: typecode
有什么想法吗?我使用的是 MySQL 方言,无法想象查询可能在哪里出错,因为它非常简单。
AccountBalance
的类型为double
。我什至用 ID
字段的平均值进行了尝试,该字段的类型为 long,但仍然收到相同的错误消息。
When I try to execute this query:
var q = session.QueryOver<Member>();
q.Select(Projections.Avg<Member>(x => x.AccountBalance));
var result = q.List();
I am getting a:
Dialect does not support DbType.Double
Parameter name: typecode
Any ideas? I am using a MySQL dialect, and cannot imagine where the query can be wrong as its quite simple.
AccountBalance
is of type double
. I've even tried it with the average of the ID
field, which is of type long, but still got the same exact error message.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
NHibernate 使用强制转换来确保
AVG
函数的返回类型。MySql 之前的版本 5 不支持
CAST
表达式中的NUMERIC
类型。 MySql 5.0.8 添加了支持 。所以你需要使用MySQL5Dialect。原始答案:
我不知道这是否有帮助,但正如我上面所说,我遇到了类似的问题。进一步挖掘后,我发现我一直在使用NHibernate.Dialect.MySQLDialect(通过FluentNHibernate.Cfg.Db.MySQLConfiguration)
来解决我的问题,我使用了MySQL5Dialect,即
希望这对你有帮助,因为我真的在抓我的往这个方向走...
NHibernate uses cast to ensure return type of
AVG
function.MySql prior version 5 does not support
NUMERIC
type inCAST
expression. The support was added in MySql 5.0.8. So you need to use MySQL5Dialect.ORIGINAL ANSWER:
I don't know if this will help, but as I said above I was having a similar problem. Upon digging a little further in I discovered that I had been using the NHibernate.Dialect.MySQLDialect (via FluentNHibernate.Cfg.Db.MySQLConfiguration)
To fix my problem I used the MySQL5Dialect instead, i.e.
Hope this helps you as I was really scratching my head on this one...
更改配置文件或引导程序上的方言
change the dialect on the config file or bootstrapping