MicroLite 5.2 upcoming features

MicroLite 5.2 is currently in development, you can see the progress by checking the GitHub 5.2 Milestone

We’ll cover the changes in greater detail once MicroLite 5.2 has been released, however here’s a sneak preview of some of the changes:

Includes

We have added a callback action which can be registered when specifying an include:

At the moment, if you want to use the Include functionality and store the result in a field, you need to do something like this:

var includeCustomer = session.Include.Single<Customer>(12345);

... // Something which results in the query being executed

this.customer = includeCustomer.Value;

The new callback functionality will allow you to express that same logic like this:

session.Include.Single<Customer>(12345)
    .OnLoad(include => this.customer = include.Value);

Read Only classes

Prior to MicroLite 5.2, we required that classes had an identifier mapped so that they could be used for select by Id, insert, update and delete calls. We added the dynamic projection support to allow ad-hoc select queries but sometimes it is still nice to have a typed class. Also, dynamics are not supported in .NET 3.5 so the .NET 3.5 build of MicroLite does not offer it.

To remove this limitation, we are adding support for read only classes.

If you are using the Attribute Based Mapping, simply don’t decorate the class with the [Identifier(IdentifierStrategy.DbGenerated)] attribute.

If you are using the Convention Based Mapping, don’t add an Id or {Class}Id property.

// Convention mapped read-only class (no identifier required)
public class CustomerSummary
{
    public string Name { get; set; }
    public int Age { get; set; }
}

Example usage:

var sqlQuery = new SqlQuery(
    "SELECT Name, Age FROM Customer WHERE CustomerId = @p0",
    1024);

var customerSummary = session.Single<CustomerSummary>(sqlQuery);

Console.WriteLine(customerSummary.Name);
Console.WriteLine(customerSummary.Age);

Read only classes will be supported by the following methods:

ISession.Include.Many<T>();
ISession.Include.Single<T>(SqlQuery);
ISession.Fetch<T>();
ISession.Paged<T>();
ISession.Single<T>(SqlQuery);

Tuples

MicroLite has had support for dynamic projections since MicroLite 2.0 and the functionality was extended and simplified more recently in MicroLite 4.0.

In addition to dynamic results, we are now adding support for Tuples which will allow you to do the following:

var sqlQuery = new SqlQuery(
    "SELECT Name, Age FROM Customer WHERE CustomerId = @p0",
    1024);

var tuple = session.Single<Tuple<int, string>>(sqlQuery);

Console.WriteLine(tuple.Item1);
Console.WriteLine(tuple.Item2);

Tuples will be supported for use in the following methods and will support singletons (one item) through to septuples (seven items) and be available in the .NET 4.0 and .NET 4.5 builds of MicroLite.

ISession.Include.Many<Tuple<T>>();
ISession.Include.Single<Tuple<T>>(SqlQuery);
ISession.Fetch<Tuple<T>>();
ISession.Paged<Tuple<T>>();
ISession.Single<Tuple<T>>(SqlQuery);

SQL Builder

NOT LIKE

var sqlQuery = sqlBuilder
    .Select("*")
    .From("Table")
    .Where("Column1")
    .IsNotLike("FOO%")
    .ToSqlQuery();

This gives us the equivalent negative for .IsLike("FOO%").

NOT BETWEEN

var sqlQuery = sqlBuilder
    .Select("*")
    .From("Table")
    .Where("Column1")
    .NotBetween(1, 10)
    .ToSqlQuery();

This gives us the equivalent negative for .Between(1, 10).

EXISTS and NOT EXISTS

var subQuery = new SqlQuery(
    "SELECT Id FROM Table WHERE Column = @p0",
    1024);

var sqlQuery = sqlBuilder
    .Select("*")
    .From("Table")
    .Where()
    .Exists(subQuery)
    .ToSqlQuery();

var sqlQuery = sqlBuilder
    .Select("*")
    .From("Table")
    .Where()
    .NotExists(subQuery)
    .ToSqlQuery();

DISTINCT

var sqlQuery = sqlBuilder
    .Select()
    .Distinct("Column")
    .From("Table")
    .ToSqlQuery();

The aim is to have MicroLite 5.2 finished by 20th August 2014, keep an eye out for it on nuget.org.

Advertisements

2 thoughts on “MicroLite 5.2 upcoming features

  1. Pingback: MicroLite 5.2 Beta | MicroLite ORM

  2. Pingback: MicroLite 5.2 Released | 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