【问题标题】:Fluent Nhibernate mysql date problemsFluent Nhibernate mysql日期问题
【发布时间】:2012-05-02 19:45:50
【问题描述】:

当 MySql 中的日期时间字段等于“0000-00-00 00:00:00”时,NHibernate 无法将其转换为 .net 日期时间。

错误信息:

"Unable to convert MySQL date/time value to System.DateTime"

如何配置 Fluent NHibernate 以将值转换为 null 或 datetime.min?

编辑:

我试过这个: NHibernate Unable to convert MySQL date/time value to System.DateTime 但它不起作用。 这是我的配置:

string connectionString = "Server=SERVER;Port=3306;Database=DB;Uid=USER;Pwd=PASSWORD; Allow Zero Datetime=true;";
        return Fluently.Configure()
          .Database(MySQLConfiguration
                        .Standard
                        .ConnectionString(connectionString)
                        )
         .Mappings(m => 
                        m.FluentMappings
                        .AddFromAssemblyOf<MyMapping>()
                    )
         .BuildSessionFactory()
         ;

【问题讨论】:

标签: mysql nhibernate datetime fluent-nhibernate


【解决方案1】:

我提到的帖子有关于转换零日期时间的建议,我在您的配置中没有看到它。

你试过这样吗:

string connectionString = "Server=SERVER;Port=3306;Database=DB;Uid=USER;Pwd=PASSWORD; Allow Zero Datetime=true;Convert Zero Datetime=true";
        return Fluently.Configure()
          .Database(MySQLConfiguration
                        .Standard
                        .ConnectionString(connectionString)
                        )
         .Mappings(m => 
                        m.FluentMappings
                        .AddFromAssemblyOf<MyMapping>()
                    )
         .BuildSessionFactory()
         ;

【讨论】:

  • 谢谢!我没有看到转换语句。现在可以了!
猜你喜欢
  • 2010-11-17
  • 2010-10-29
  • 1970-01-01
  • 1970-01-01
  • 2013-09-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多