I got this exception
at System.Convert.ToDateTime(Object value)
at NHibernate.Type.DateTimeType.Get(IDataReader rs, Int32 index) in p:\\nhibernate
I would expect that you are using SQL Server, where timestamp
is not a DateTime
value. Nothing in common. See (the up-to-date name is rowversion
) - rowversion (Transact-SQL)
Is a data type that exposes automatically generated, unique binary numbers within a database. rowversion is generally used as a mechanism for version-stamping table rows. The storage size is 8 bytes. The rowversion data type is just an incrementing number and does not preserve a date or a time. To record a date or time, use a datetime2 data type.
What I would suggest, do use that type of column (rowversion/timestamp) as you did, with conjunction of NHiberante power of
attribute. See:
There is a snippet of the mapping:
If we need to pass that binary stuff to client we can do some conversion into string property, see:
property as a C# code:
protected virtual byte[] Timestamp { get; set; }
public virtual string Version
{
get { return Timestamp.IsEmpty() ? null : Convert.ToBase64String(Timestamp); }
set { Timestamp = value.IsEmpty() ? null : Convert.FromBase64String(value); }
}