-
Notifications
You must be signed in to change notification settings - Fork 302
Version column support
petsuter edited this page Aug 11, 2015
·
3 revisions
A numeric version field can be used to detect conflicting updates:
[TableName("Users")]
[PrimaryKey("UserId")]
public class User
{
public int UserId { get;set; }
[VersionColumn("VersionInt", VersionColumnType.Number)]
public long VersionInt { get; set; }
}
Updates will automatically check and increment the version and throw DBConcurrencyException
if it is outdated. This can be disabled by setting Database.VersionException = VersionExceptionHandling.Ignore
.
In SQL Server a rowversion
timestamp datatype can be used for the version column with VersionColumnType.RowVersion
:
[TableName("Users")]
[PrimaryKey("UserId")]
public class User
{
public int UserId { get;set; }
[VersionColumn("Version", VersionColumnType.RowVersion)]
public byte[] Version { get; set; }
}