Skip to content
This repository was archived by the owner on Dec 29, 2020. It is now read-only.

Using Microsoft SQL Server

TrevorPilley edited this page Nov 4, 2014 · 3 revisions

Version Support

MicroLite is built to work with any version of Microsoft SQL Server from 2005 onwards and uses the SqlClient provider supplied with the .NET framework.

Connection String

Add a named connection string for your Database specifying the provider name. It should look similar to this (note that the provider name is required):

<connectionStrings>
    <add name="NorthwindDB"
         connectionString="Data Source=localhost;Initial Catalog=Northwind;Persist Security Info=False;Integrated Security=SSPI;"
         providerName="System.Data.SqlClient" />
</connectionStrings>

Configuring the Connection

Create a session factory using the ForMsSql2005Connection or ForMsSql2012Connection 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()
        .ForMsSql2005Connection("NorthwindDB")
        .CreateSessionFactory();

    ...
}

The ForMsSql2005Connection supports MS SQL Server 2005 onwards, ForMsSql2012Connection supports MS SQL Server 2012 onwards. Use the version which supports the lowest version of SQL your application will connect to.

Supported Identifier Strategies

MicroLite supports the following Identifier Strategies for MS SQL 2005:

  • Assigned
  • DbGenerated

In addition it also supports the following Identifier Strategies for MS SQL 2012:

  • Sequence
Clone this wiki locally