-
Notifications
You must be signed in to change notification settings - Fork 0
State version pattern
arbinada-com edited this page Apr 23, 2020
·
1 revision
State version pattern provide the version number for every domain object and rows of underlying tables.
There are two main objectives of this pattern:
- Avoid rewriting persistent data when two or more processes modify the same object. NHibernate domain layer will throw an exception if the version of saved object is not the same that current persistent value.
- Modifications counter with possibility to extend this pattern with save all history of data changes, see Tracking-changes-pattern
By default, an attribute Version of integer type will be added to every domain object/table. You can change the name and type if needed.
<Pattern name="StateVersion">
<Param name="Attribute.Name" value="ObjectVersion" />
<Param name="Attribute.Type" value="shortint" />
</Pattern>
| Parameter name | Required? | Description |
|---|---|---|
| Attribute.Name | Optional | Name of attribute used to implement version counter. Default is "Version". |
| Attribute.Type | Optional | Type of version attribute. Default is "int" |
Currency currency = new Currency();
currency.Code = "USD";
currency.Name = "US dollar";
currency.Save();
Console.WriteLine("Currency '{0}' version is {1}",
currency.Code,
currency.Version);