-
Notifications
You must be signed in to change notification settings - Fork 24
Using MySQL
MicroLite is built to work with any version of MySQL from 5.5 onwards but requires MySql.Data to be installed as the .NET framework does not ship a native provider for MySQL.
Install the MySql.Data nuget package:
Install-Package MySql.Data
Add the section to your app.config/web.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=6.8.3.0, 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.
Add a named connection string for your Database specifying the provider name.
<connectionStrings>
<add name="MySQLTest"
connectionString="Server=localhost;Database=database;Uid=User;Pwd=Pswd;"
providerName="MySql.Data.MySqlClient" />
</connectionStrings>
Create a session factory using the ForMySqlConnection
extension method supplying the name of the connection string you added to the app.config/web.config.
using MicroLite;
using MicroLite.Configuration;
static void Main(string[] args)
{
var sessionFactory = Configure
.Fluently()
.ForMySqlConnection("MySQLTest")
.CreateSessionFactory();
...
}
MicroLite supports the following Identifier Strategies for MySQL:
- Assigned
- DbGenerated (using identity columns)
See the Getting Started guide for further details on using MicroLite.