Author Archives: trev

MicroLite.Extensions.Mvc 6.3.0

MicroLite.Extensions.Mvc 6.3.0 has been released on NuGet.

The main changes in this release are:

  1. .NET 4.5 only build targeting ASP.NET MVC 5.2.3
  2. MicroLiteSessionAttribute has been removed, it is strongly recommended that you use an IOC container to manage dependencies.

This does mean that the release is not necessarily a “drop-in” update if you were previously using an older version of .NET or ASP.NET MVC.

To see the full set of changes, please refer to the Github release page

MicroLite.Extensions.WebApi 6.5.0

MicroLite.Extensions.WebApi 6.5.0 has been released on NuGet.

The main changes in this release are:

  1. .NET 4.5 only build targeting ASP.NET WebApi 5.2.3 and Net.Http.WebApi.OData 3.4.0
  2. MicroLiteSessionAttribute has been removed, it is strongly recommended that you use an IOC container to manage dependencies.

This does mean that the release is not necessarily a “drop-in” update if you were previously using an older version of .NET or ASP.NET WebApi.

To see the full set of changes, please refer to the Github release page

Logging Extension Updates

The logging extensions for MicroLite have been updated as follows and are available on nuget.org.

log4net

The log4net extension has been updated to target log4net 2.0.5 or later and a .NET 4.6 compiled build has been added.

NLog

The NLog extension has been updated to target NLog 4.4.0 or later and a .NET 4.6 compiled build has been added.

Serilog

The Serilog extension has been updated to target Serilog 2.3.0 or later, a .NET 4.6 compiled build has been added and the .NET 4.0 build has been removed.

MicroLite 6.3.1

MicroLite 6.3.1 has been released and it is strongly recommended that anyone using 6.3.0 upgrades immediately.

A defect has been identified in 6.3.0 whereby the Identifier value of a newly inserted record isn’t set on the object. This was inadvertently introduced when the Listener code was refactored in 6.3.0 so it only affects that version which has now been hidden on nuget.org.

Upgrading to MicroLite 6.3

MicroLite 6.3.0 has been released on NuGet, the main changes in this release are detailed below.

New Convention Mappings

There are now 2 new helper convention mappings:

  1. ConventionMappingSettings.LowercaseWithUnderscores – Maps a Pascal Cased property name to an underscore separated lower cased column e.g. a property called ‘CreditCard’ would map to a column called ‘credit_card’
  2. ConventionMappingSettings.UppercaseWithUnderscores – Maps a Pascal Cased property name to an underscore separated upper cased column e.g. a property called ‘CreditCard’ would map to a column called ‘CREDIT_CARD’

DateTime mapping

The default mapping for System.DateTime is now System.Data.DbType.DateTime2. If you need to change it back to System.Data.DbType.DateTime do the following:

// In startup code (before calling Configure.Fluently()...):

// Reset the DbType mapping for DateTime:
TypeConverter.RegisterTypeMapping(typeof(DateTime), DbType.DateTime);
TypeConverter.RegisterTypeMapping(typeof(DateTime?), DbType.DateTime);

XDocument mapping

The default mapping for System.Xml.Linq.XDocument is now System.Data.DbType.Xml. If you need to change it back to System.Data.DbType.String do the following:

// In startup code (before calling Configure.Fluently()...):

// Reset the DbType mapping for XDocument:
TypeConverter.RegisterTypeMapping(typeof(XDocument), DbType.String);

MicroLite 6.3

MicroLite development has been quiet for a while, although I have some plans for version 7.0, they are quite big and as part of that is moving to support .NET Core it’s a way off. In the interim I’m planning another build for version 6 which will pull some of the quicker and easier changes which were waiting for 7.0.

The biggest change will be that the support for databases other than MS SQL will be moved into separate libraries which reference the third party drivers explicitly. The only real impact will be pulling in MicroLite.Database.<DbType> in addition to MicroLite if you use MySQL, PostgreSQL etc.

To see what else is to be included, view the milestone for 6.3

Edit 24 Aug 2016: The split for databases into separate projects will now not happen until MicroLite 7.0 to avoid introducing a breaking change in 6.3

Matching Database Types

In order for SQL queries to perform as fast as possible, it is important to ensure that the types you use in your .NET code match the types you use in your database. This is especially important when you have indexes because if the data type of the SQL parameter doesn’t match the data type of the column, the index for that column won’t be used!

Consider the following table and class:

CREATE TABLE [dbo].[Customers]
(
    [Id] [int] IDENTITY(1,1) NOT NULL,
    [Forename] NVARCHAR(50) NOT NULL,
    [Surname] NVARCHAR(50) NOT NULL,
    [DateOfBirth] DATETIME2 NOT NULL,
    [CustomerStatusId] INT NOT NULL
)
public class Customer
{
    public int Id { get; set; }
    public string Forename { get; set; }
    public string Surname { get; set; }
    public DateTime DateOfBirth { get; set; }
    public CustomerStatus Status { get; set; }
}

The default configuration of MicroLite is to map string to DbType.String (NVARCHAR) since .NET strings are unicode. If you don’t use unicode columns in your database, you should change the default type mapping for strings as follows:

// Map strings as ANSI instead of unicode
TypeConverter.RegisterTypeMapping(typeof(string), DbType.AnsiString);

Also, the default mapping for DateTime is to DbType.DateTime so if you use DATETIME2 columns, you should change the default mapping as follows:

// Always use DbType.DateTime2 instead of DbType.DateTime for System.DateTime
TypeConverter.RegisterTypeMapping(typeof(DateTime), DbType.DateTime2);

Note, in MicroLite 7 we plan to change the default DateTime mapping to DbType.DateTime2.

You can see the full set of default mappings Here