34

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:

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

2 Answers 2

49

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

Example:

Fluently.Configure().Database(
        MySqlConfiguration.Standard.ConnectionString(
            c => c.FromConnectionStringWithKey("ConnectionString")
        )
    )
    .Mappings(m => m.FluentMappings.AddFromAssemblyOf<MyAutofacModule>())
    .BuildSessionFactory())
Sign up to request clarification or add additional context in comments.

8 Comments

Thank you, funny I missed this.
signed in just to vote you guys up. now, can someone help me with nhibernate? i get error unable to create drive for mysql
Cool, you might want to ask a whole new question with as much details as you can possibly give. I'm not familiar with that error off hand, so I can't give you much help without more details. I will say that the error sounds unusual, I don't think I've ever got that one and I mess around with Fluent NHib and MySql all the time.
Yes, I did need a driver from MySql Connector, specifically a reference to MySql.Data. I don't think the version is relevant as long as it's not an ancient one. I've never had a problem in terms of which version I was using. I don't think FluentNhibernate directly references the MySql.Data library, so there should not be a version mismatch.
I actually was able to solve the problem using MySQLcon... instead of MySql... it has had to have changed, because in every resource I see how you have it. Thank you for the response good sir.
|
0
var SessionFactory = Fluently.Configure()
    .Database(MySQLConfiguration.Standard.ConnectionString(connectionString))
    .Mappings(m => m.FluentMappings.AddFromAssembly(Assembly.GetExecutingAssembly()))
    .BuildSessionFactory();`

Try this Configuration.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.