Nhibernate - Dialect does not support DbType.Double
2013-01-28 15:19 Fred-Xu 阅读(896) 评论(0) 编辑 收藏 举报引用的文件:
Fluent Nhibernate 1.3.0
Nhibernate 3.3.1
.NET Framework 4.0
MySQL 5.0
在统计模块里需要用到sum这个函数,这里有一个测试方法来统计某一条件的总价(美元),TotalCostUsd是一个double?类型,
[TestMethod] public void TestMethod1() { NHibernateHelper helper = new NHibernateHelper(_connectionString); UnitOfWork unitOfWork = new UnitOfWork(helper.SessionFactory); IRepository<Order> repository = new GenericRepository<Order>(unitOfWork.Session); var list = repository.FilterBy(o => o.Factory.Code.Equals("A8") && o.State == OrderState.ConfirmShipping); var total = list.Sum(o => o.TotalCostUsd) ?? 0D; Assert.AreEqual(100, total); }
测试结果报出来这个错误:
Dialect does not support DbType.Double
第一反应是MySQL不支持double类型?这不可能啊...LINQ不支持double类型?这也不可能啊...
http://www.blogjava.net/Alpha/archive/2008/04/15/193094.html
https://community.jboss.org/wiki/DatabasesSupportedByNHibernate?_sscc=t
我把配置修改为:
private ISessionFactory CreateSessionFactory() { return Fluently.Configure() .Database(MySQLConfiguration.Standard.Dialect<MySQL5Dialect>().ConnectionString(_connectionString)) .Mappings(m => m.FluentMappings.AddFromAssembly(typeof(PekingHandicraftPMS.Data.NHibernateMapping.UserMap).Assembly) ) //.ExposeConfiguration(CreateSchema) .BuildSessionFactory(); }
增加
Dialect<MySQL5Dialect>()
Run Tests.....
It works!