One of the updates in MicroLite 3.0 was support for MySQL, however there are a couple of things you need to do if you wish to use MySQL which you don’t for MS SQL. This is due to the fact that the .NET framework supports MS SQL natively, whereas the MySQL implementations of the System.Data classes are provided by MySQL.com.
As usual you will still need to add a named connection string to your app.config:
<connectionStrings> <add name="MySQLTest" connectionString="Server=localhost;Database=database;Uid=User;Pwd=Pswd;" providerName="MySql.Data.MySqlClient" /> </connectionStrings>
You also need to add another section to your app.config so that the .NET framework knows about the MySql.Data provider:
<system.data> <DbProviderFactories> <remove invariant="MySql.Data.MySqlClient" /> <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description="ADO.Net driver for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=220.127.116.11, Culture=neutral, PublicKeyToken=c5687fc88969c44d" /> </DbProviderFactories> </system.data>
Make sure that the version specified matches the version you have installed or you will get an exception thrown by the .NET runtime at startup when it tries to resolve the assembly.
Then finally, in you application startup, you need to call the overload method for
ForConnection so that you can specify the MySqlDialect:
var sessionFactory = Configure .Fluently() .ForConnection(connectionName: "MySQLTest", sqlDialect: "MicroLite.Dialect.MySqlDialect") .CreateSessionFactory();
This article was written for version 3.0.0 of the MicroLite framework.
As of MicroLite 4.0.1, use the
ForMySqlConnection method instead:
var sessionFactory = Configure .Fluently() .ForMySqlConnection("MySQLTest") .CreateSessionFactory();