简体   繁体   English

如何使用 MySQL 配置流畅的 nHibernate

[英]How to configure fluent nHibernate with MySQL

I'm trying to configure nHibernate to use a MySql database.我正在尝试将 nHibernate 配置为使用 MySql 数据库。 I found examples for mssql and sqlite but none for mysql.我找到了 mssql 和 sqlite 的示例,但没有找到 mysql 的示例。 So, how do I change this so it uses mysql:那么,我该如何更改它以使其使用 mysql:

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

Change MsSqlConfiguration.MsSql2005 , to MySqlConfiguration.Standard , it was the one thing I contributed to the project. MsSqlConfiguration.MsSql2005更改为MySqlConfiguration.Standard ,这是我为该项目做出贡献的一件事。

Example:例子:

Fluently.Configure().Database(
        MySqlConfiguration.Standard.ConnectionString(
            c => c.FromConnectionStringWithKey("ConnectionString")
        )
    )
    .Mappings(m => m.FluentMappings.AddFromAssemblyOf<MyAutofacModule>())
    .BuildSessionFactory())
var SessionFactory = Fluently.Configure()
    .Database(MySQLConfiguration.Standard.ConnectionString(connectionString))
    .Mappings(m => m.FluentMappings.AddFromAssembly(Assembly.GetExecutingAssembly()))
    .BuildSessionFactory();`

Try this Configuration.试试这个配置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM