Nhibernate使用.Sum()和.Average()方法时,会报Dialect does not support DbType.Double或者Dialect does not support DbType.Decimal错误,这是因为翻译成sql语句时,NHibernate使用cast来确保AVG或Sum函数的返回类型。之前的MySql版本5不支持转换表达式中的数值类型。在MySql 5.0.8中添加了支持。所以你需要使用mysql5方言(MySQL5Dialect)。
解决方法:
1、修改配置文档
原:<property name="dialect">NHibernate.Dialect.MySQLDialect</property>
更改为:<property name="dialect">NHibernate.Dialect.MySQL5Dialect</property>
2、
private ISessionFactory CreateSessionFactory()
{
return Fluently.Configure()
.Database(MySQLConfiguration.Standard.Dialect<MySQL5Dialect>().ConnectionString(_connectionString))
.Mappings(m => m.FluentMappings.AddFromAssembly(typeof(PekingHandicraftPMS.Data.NHibernateMapping.UserMap).Assembly)
)
.BuildSessionFactory();
}