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:

Configure
    .Fluently()
    .ForConnection(connectionName: "SQLiteTest", sqlDialect: "MicroLite.Dialect.SQLiteDialect")
    .CreateSessionFactory();

SqlDialect

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);
MicroLite.Dialect.SQLiteDialect

Changes/Enhancements

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:

Between

var query = SqlBuilder
    .Select("*")
    .From(typeof(Customer))
    .Where("DateRegistered")
    .Between(new DateTime(2000, 1, 1), new DateTime(2009, 12, 31))
    .ToSqlQuery();

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

In – 2 overloads

var query = SqlBuilder
    .Select("*")
    .From(typeof(Customer))
    .Where("Column1")
    .In("X", "Y", "Z")
    .ToSqlQuery();

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

var customerQuery = SqlBuilder
    .Select("CustomerId")
    .From(typeof(Customer))
    .Where("Age > @p0", 40)
    .ToSqlQuery();

var query = SqlBuilder
    .Select("*")
    .From(typeof(Invoice))
    .Where("CustomerId")
    .In(customerQuery)
    .ToSqlQuery();

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

There are 2 new Identifier Strategy options:

IdentifierStrategy.GuidComb
IdentifierStrategy.AutoIncrement

GuidComb

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:

47d8e8bf-b4f7-4c0b-9ad6-7396a11e7569
18b0913f-2a12-4a0e-a077-b3ea67a61acb

The Guid Comb strategy on the other hand:

1612060b-d10f-4fe0-e1df-08cf8a62c896
1612060b-d10f-4fe0-e1e0-08cf8a62c896

AutoIncrement

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

Obsolete

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.

Advertisements

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.

      Reply
  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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s