Table of Contents

Class UnitOfWork

Namespace
ArcanaDevelopment.adTempus.Client
Assembly
ArcanaDevelopment.adTempus.Client.dll

A UnitOfWork is a group of object saves and deletions that are sent to the server in one call and executed in one transaction

public class UnitOfWork
Inheritance
object
UnitOfWork

Remarks

Use a UnitOfWork to perform atomic updates and deletions on adTempus objects. All operations added to the UnitOfWork are sent to the server in a single call, and the object validation and database updates are performed in a single transaction, so that if any of the operations fail none will be committed.

After adding operations to the UnitOfWork using AddForSave(ADTIndependentObject, ChangeLogParameters) and AddForDelete(ADTIndependentObject, ChangeLogParameters), call Commit() to commit the changes to the server. To discard the changes without saving, simply discard the UnitOfWork: there is no explicit rollback method.

If you want to reuse a UnitOfWork that has bot been committed, call Clear() first to empty it.

The order in which actions are added to the UnitOfWork does not matter: the server will sequence actions properly based on dependencies.

Use CreateUnitOfWork() to create a new UnitOfWork.

A UnitOfWork can only contain objects that belong to the same DataContext as the UnitOfWork. If you try to add an object from another DataContext you will get a BoundaryViolationException

Methods

AddForDelete(ADTIndependentObject, ChangeLogParameters)

Adds an object to be deleted

public void AddForDelete(ADTIndependentObject objectToDelete, ChangeLogParameters auditRecord = null)

Parameters

NameTypeDescription
objectToDelete ADTIndependentObject

The object to delete. The object must belong to the same DataContext as the UnitOfWork

auditRecord ChangeLogParameters

Optional information to use when creating an audit record for the operation

Exceptions

BoundaryViolationException

Thrown if the objectToDelete belongs to a different DataContext than the UnitOfWork does

AddForSave(ADTIndependentObject, ChangeLogParameters)

Adds a new or modified object to be saved to the server

public void AddForSave(ADTIndependentObject objectToSave, ChangeLogParameters auditRecord = null)

Parameters

NameTypeDescription
objectToSave ADTIndependentObject

The object to save. The object must belong to the same DataContext as the UnitOfWork

auditRecord ChangeLogParameters

Optional information to use when creating an audit record for the operation

Exceptions

BoundaryViolationException

Thrown if the objectToSave belongs to a different DataContext than the UnitOfWork does

Clear()

Resets the UnitOfWOrk for reuse

public void Clear()

Remarks

The UnitOfWork is cleared automatically after a successful call to Commit().

The Clear method only needs to be called if you want to reuse the UnitOfWork. It is not necessary to call it to roll back uncommitted changes--you may simply discard the UnitOfWork.

Commit()

Commits the changes to the server

public void Commit()

Remarks

If any errors occur while processing the updates the method will throw a MessageException with information about the problem (such as data validation errors).

Exceptions

MessageException

Thrown if the operation fails