Skip to end of metadata
Go to start of metadata

You are viewing an old version of this content. View the current version.

Compare with Current View Version History

« Previous Version 5 Next »

Database structure

In Link 3 all data is divided into two databases:

  • Configuration

  • Transactional

The Configuration database holds configuration data such as partners, distributions and all the developer objects. Whereas the Transactional database holds data generated by the flow such as interchanges and documents.

Although these entities are related across databases, there are NO database constraints enforcing the data consistency.

Transactions

In many cases when updating multiple entities it makes sense to join these updates in a database transaction. This gives you the possibility to roll back ALL changes if one of them fails.

To make things easier Link 3 provides a factory called ITransactionScopeFactory that can be dependency injected into your class.

Example: Using transaction scopes

In the example below we update multiple entities in the Configuration database. If an exception occurs the changes are automatically rolled back.

using (var scope = transactionScopeFactory.CreateScope())
{
    try
    {
        //Updates to configuration data
        scope.Complete();
    }
    catch (Exception ex)
    {
        logger.LogError(ex, $"Exception occured: {ex.Message}");
    }
}

Example: Using transaction scopes across multiple databases.

Transactions that consists of updates to multiple databases are called distributed transactions. Unfortunately these types of transactions are not supported and would result in a PlatformNotSupportedException.

However it is possible to “break out” of a scope by using the method RunOutsideTransaction as seen in line 7 in the example below:

using (var scope = transactionScopeFactory.CreateScope())
{
    try
    {
        //Updates to configuration data

        await transactionScopeFactory.RunOutsideTransaction(() =>
        {
            //Updates to transactional data
        });

        scope.Complete();
    }
    catch (Exception ex)
    {
        logger.LogError(ex, $"Exception occured: {ex.Message}");
    }
}
  • No labels