【问题标题】:How to configure fluent nHibernate with MySQL如何使用 MySQL 配置流畅的 nHibernate
【发布时间】:2010-10-12 04:45:37
【问题描述】:

我正在尝试将 nHibernate 配置为使用 MySql 数据库。我找到了 mssql 和 sqlite 的示例,但没有找到 mysql 的示例。 那么,我该如何更改它以使其使用 mysql:

Fluently.Configure().Database(
        MsSqlConfiguration.MsSql2005.ConnectionString(
            c => c.FromConnectionStringWithKey("ConnectionString")
        )
    )
    .Mappings(m => m.FluentMappings.AddFromAssemblyOf<MyAutofacModule>())
    .BuildSessionFactory())

【问题讨论】:

    标签: c# mysql nhibernate fluent-nhibernate autofac


    【解决方案1】:

    MsSqlConfiguration.MsSql2005 更改为MySqlConfiguration.Standard,这是我为该项目做出的贡献。

    例子:

    Fluently.Configure().Database(
            MySqlConfiguration.Standard.ConnectionString(
                c => c.FromConnectionStringWithKey("ConnectionString")
            )
        )
        .Mappings(m => m.FluentMappings.AddFromAssemblyOf<MyAutofacModule>())
        .BuildSessionFactory())
    

    【讨论】:

    • 谢谢你,有趣的是我错过了。
    • 登录只是为了给你们投票。现在,有人可以帮助我进行休眠吗?我收到错误无法为 mysql 创建驱动器
    • 酷,你可能想问一个全新的问题,尽可能详细地提供。我不熟悉该错误,因此如果没有更多详细信息,我无法为您提供太多帮助。我会说这个错误听起来很不寻常,我想我从来没有遇到过这个错误,而且我一直在使用 Fluent NHib 和 MySql。
    • 是的,我确实需要来自 MySql 连接器的驱动程序,特别是对 MySql.Data 的引用。我不认为该版本是相关的,只要它不是一个古老的版本。就我使用的版本而言,我从来没有遇到过问题。我觉得 FluentNhibernate 没有直接引用 MySql.Data 库,所以不应该存在版本不匹配的问题。
    • 我实际上能够使用 MySQLcon... 而不是 MySql... 来解决问题...它必须改变,因为在每一个资源中我都看到了你是如何拥有它的。谢谢你的回复好先生。
    【解决方案2】:
    var SessionFactory = Fluently.Configure()
        .Database(MySQLConfiguration.Standard.ConnectionString(connectionString))
        .Mappings(m => m.FluentMappings.AddFromAssembly(Assembly.GetExecutingAssembly()))
        .BuildSessionFactory();`
    

    试试这个配置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多