MicroLite 2.1 Enhancements

A beta release of MicroLite 2.1.0 has been released on NuGet (it is scheduled for release on 12th November 2012).

MicroLite 2.1.0 adds support for SQLite, provides some enhancements and contains a few bug fixes.

SQLite – Configuration

MicroLite defaults to MS SQL Server so in order to to use SQLite you will need to use the new configuration overload:

    .ForConnection(connectionName: "SQLiteTest", sqlDialect: "MicroLite.Dialect.SQLiteDialect")


The sqlDialect parameter tells MicroLite which type of SQL to generate as there are some differences between each implementation of SQL.

The dialects currently supported in MicroLite 2.1 are:

MicroLite.Dialect.MsSqlDialect – This is the default used if you call .ForConnection(connectionName);


The IListener interface now has 2 new methods, they are both implemented as virtual in the Listener base class with empty implementations:

void AfterDelete(object instance, int rowsAffected);
void AfterUpdate(object instance, int rowsAffected);

The SqlBuilder class has 2 new methods:

Between(object lower, object upper);
In(params object[] args);
In(SqlQuery subQuery);

Which enable us to do the following:


var query = SqlBuilder
    .Between(new DateTime(2000, 1, 1), new DateTime(2009, 12, 31))

SELECT {Columns} FROM Customers WHERE (DateRegistered BETWEEN @p0 AND @p1)

In – 2 overloads

var query = SqlBuilder
    .In("X", "Y", "Z")

SELECT {Columns} FROM Customers WHERE (Column1 IN (@p0, @p1, @p2))

var customerQuery = SqlBuilder
    .Where("Age > @p0", 40)

var query = SqlBuilder

SELECT {Columns} FROM Invoices WHERE (CustomerId IN (SELECT CustomerId FROM Customers WHERE Age > @p0))

There are 2 new Identifier Strategy options:



Guid Comb is used to create GUIDs which respect SQL sorting algorithms to reduce index fragmentation over the standard GUID implementation in .NET whilst still generating unique values. It offers the same benefits as IdentifierStrategy.Guid (the identifier is generated on the client) while offering improvements for the database engine.

For example, the standard Guid strategy gives wildly different values:


The Guid Comb strategy on the other hand:



Auto Increment is the SQLite equivalent of IdentifierStrategy.Identity, it should only be used if you are using SQLite (likewise Identity should only be used for MS SQL Server).

Table Schema

The schema parameter for the TableAttribute is now optional as SQLite doesn’t support the concept of table schemas. You can still specify a schema if you want to for MS SQL Server.

[Table("Customers")] // works for SQLite and MsSqlServer
// or
[Table(schema: "Sales", name: "Customers")] // works for MsSqlServer only, DO NOT USE with SQLite


The ISession.Advanced.Projection method has been obsoleted and moved to ISession.Projection, the method on .Advanced will be removed in MicroLite 3.0.

Bug Fixes

Issue #110 – GuidListener should throw MicroLiteException if instance has Identifier set when calling BeforeInsert.
Issue #118 – All IListeners should do the same check in BeforeUpdate as BeforeDelete.
Issue #130 – PagedResults shows incorrect Total Pages.


4 thoughts on “MicroLite 2.1 Enhancements

    1. trevorpilley Post author

      It’s some weird html encoding bug, not sure why it happens as it was fine yesterday (I think it’s something related to the iOS wordpress app). I’ve corrected them now.

  1. Pingback: SqlBuilder Updates | MicroLite ORM

  2. Pingback: Using SQLite | MicroLite ORM

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s