MicroLite 5.0 – Changes to IdentifierStrategy

One of the changes coming in MicroLite 5.0 is the removal of the IdentifierStrategy options for Guid and GuidComb.

If you currently use either of them, you can maintain the functionality by using the Assigned IdentifierStrategy and creating a custom IListener to set the value.

using System;
using MicroLite.Listeners;
using MicroLite.Mapping;

public class GuidListener : Listener
    public override void BeforeInsert(object instance)
        var objectInfo = ObjectInfo.For(instance.GetType());

        if (objectInfo.TableInfo.IdentifierColumn.PropertyInfo.PropertyType == typeof(Guid))
            var identifier = Guid.NewGuid();

            objectInfo.SetIdentifierValue(instance, identifier);

If you used the GuidComb strategy, you can find the code to generate the next GUID here and use this line instead:

var identifier = GuidGenerator.CreateComb();

1 thought on “MicroLite 5.0 – Changes to IdentifierStrategy

  1. Pingback: MicroLite 5.0 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 )

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