C# 如何使用 MySQL 配置流畅的 nHibernate

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/626339/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 10:49:34  来源:igfitidea点击:

How to configure fluent nHibernate with MySQL

c#mysqlnhibernatefluent-nhibernateautofac

提问by Spikolynn

I'm trying to configure nHibernate to use a MySql database. I found examples for mssql and sqlite but none for mysql. So, how do I change this so it uses mysql:

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

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

采纳答案by Mark Rogers

Change MsSqlConfiguration.MsSql2005, to MySqlConfiguration.Standard, it was the one thing I contributed to the project.

更改MsSqlConfiguration.MsSql2005MySqlConfiguration.Standard,这是我为该项目贡献的一件事。

Example:

例子:

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

回答by Mohit Arora

var SessionFactory = Fluently.Configure()
    .Database(MySQLConfiguration.Standard.ConnectionString(connectionString))
    .Mappings(m => m.FluentMappings.AddFromAssembly(Assembly.GetExecutingAssembly()))
    .BuildSessionFactory();`

Try this Configuration.

试试这个配置。