Support for Sequences

Sequences are used in some databases as an alternative to identity or auto increment columns. As of MicroLite 5.3, sequence support has been added for the following databases:

  • MS SQL 2012 or newer
  • Firebird

If you wish to use sequences, you will need to alter how you configure identifiers for mapped classes:

If you use attribute based mapping, change to use IdentifierStrategy.Sequence and also specify the sequence name:

[Identifier(IdentifierStrategy.Sequence, "CustomerIdSequence")]
public int Id { get; set; }

If you use convention based mapping, you will need to specify a convention in the configuration (for example, “ClassName_IdName_Sequence” – e.g. Customer_Id_Sequence):

ResolveSequenceName = (PropertyInfo propertyInfo) =>
    return propertyInfo.DeclaringType.Name + "_" + propertyInfo.Name + "_Sequence";

That’s all there is to it, MicroLite will take care of assigning the sequence value to the identifier property after performing an Insert (as it does with IdentifierStrategy.DbGenerated).


Leave a Reply

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

You are commenting using your 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