Reading SQL Timestamp in Castle ActiveRecord

The timestamp field in SQL Server (which is a unique number for every insert/update in the database) can be accessed in ActiveRecord as a byte array (of 8 bytes):

[Property]        
public  Byte[] Timestamp { get; set; }

This can be converted to a hexadecimal string representation with the BitConverter class:

return BitConverter.ToString(Timestamp).Replace("-", String.Empty);

Timestamp is very useful if you want to keep track of changes to records, as SQL server manages the field for you, and has total precision, unlike a datetime field.

Advertisements