Nhibernate - Dialect does not support DbType.Double

引用的文件:

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!

转载于:https://www.cnblogs.com/Fred_Xu/archive/2013/01/28/nhibernate-dialect-does-not-support-dbtype-double.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值