Sequences

Table Of Contents

What are Sequences?

This feature in The Sharp Factory Framework allows the developer to call SQL Sequences.

Sequences in SQL generate sequential numbers much like Identity fields. These incremental numbers are global to the entire database.

These sequences are bound to a particular SQL Schema.

The Sharp Factory App generates a method per SQL Sequence added to the model.

The naming convention is RepositoryContainer.{Model Name}.{SQL Schema}.Sequences.{Sequence Name}

Calling Sequences

The following C# code sample shows how to consume a SQL Sequence called CustomerID.

C#
// declare an instance of the Repository Container

// remember this can be a singleton if you

// declare it early on and reuse it for the

// lifetime of your application

var repo = new RepositoryContainer();

// call the sequence called CustomerID and get the next number

var nextNumber = _repo.AppDb.Sales.Sequences.CustomerID();

// do something with the next sequential number