views:

2726

answers:

1

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())
+14  A: 

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())
Mark Rogers
Thank you, funny I missed this.
Spikolynn
signed in just to vote you guys up. now, can someone help me with nhibernate? i get error unable to create drive for mysql
jake
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.
Mark Rogers
Did you need to install any software for this to work? I'm new to NHibernate and MySQL... In particular, did you install MySql Connector, and if so what version?
Frank Schwieterman
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.
Mark Rogers