您的位置:首页 > 其它

Nhibernate - Dialect does not support DbType.Double

2013-01-28 15:19 423 查看
引用的文件:

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类型?这也不可能啊...

Dialect?
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!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: