Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nhibernate - Dialect does not support DbType.Double

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.

like image 770
Karl Cassar Avatar asked Nov 18 '25 06:11

Karl Cassar


1 Answers

NHibernate uses cast to ensure return type of AVG function.

MySql prior version 5 does not support NUMERIC type in CAST 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.

Fluently.Configure().Database(MySQLConfiguration.Standard
    .Dialect<MySQL5Dialect>()
    .ConnectionString(connectionString))

Hope this helps you as I was really scratching my head on this one...

like image 92
PeterFearn Avatar answered Nov 19 '25 19:11

PeterFearn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!