Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you grab the NHib source code, there's a class in a test project that will help you with what you need: NHibernate.Test.VersionTest.Db.MsSQL.BinaryTimestamp. Basically, you have to give it a custom type it can use to convert the value. Be default NHib expects the value to be an int (look at seciont 5.1.7 of <a href="http://nhibernate.info/doc/nh/en/index.html#mapping-declaration-timestamp" rel="nofollow noreferrer">the nhib docs</a>). If you use an int/bigint as your version column, you will not need a custom type.</p> <p>The custom class (lifted from NHib source code):</p> <pre><code>public class BinaryTimestamp : IUserVersionType { #region IUserVersionType Members public object Next(object current, ISessionImplementor session) { return current; } public object Seed(ISessionImplementor session) { return new byte[8]; } public object Assemble(object cached, object owner) { return DeepCopy(cached); } public object DeepCopy(object value) { return value; } public object Disassemble(object value) { return DeepCopy(value); } public int GetHashCode(object x) { return x.GetHashCode(); } public bool IsMutable { get { return false; } } public object NullSafeGet(IDataReader rs, string[] names, object owner) { return rs.GetValue(rs.GetOrdinal(names[0])); } public void NullSafeSet(IDbCommand cmd, object value, int index) { NHibernateUtil.Binary.NullSafeSet(cmd, value, index); } public object Replace(object original, object target, object owner) { return original; } public System.Type ReturnedType { get { return typeof(byte[]); } } public SqlType[] SqlTypes { get { return new[] { new SqlType(DbType.Binary, 8) }; } } public int Compare(object x, object y) { var xbytes = (byte[])x; var ybytes = (byte[])y; return CompareValues(xbytes, ybytes); } bool IUserType.Equals(object x, object y) { return (x == y); } #endregion private static int CompareValues(byte[] x, byte[] y) { if (x.Length &lt; y.Length) { return -1; } if (x.Length &gt; y.Length) { return 1; } for (int i = 0; i &lt; x.Length; i++) { if (x[i] &lt; y[i]) { return -1; } if (x[i] &gt; y[i]) { return 1; } } return 0; } public static bool Equals(byte[] x, byte[] y) { return CompareValues(x, y) == 0; } } </code></pre> <p>A sample mapping using that class:</p> <pre><code>public class Car { public virtual long CarId { get; set; } public virtual string Name { get; set; } public virtual byte[] LastModified { get; set; } public override string ToString() { return string.Format("Id: {0}, Name: {1}, Last Modified: {2}", CarId, Name, LastModified); } } public class CarMap : ClassMapping&lt;Car&gt; { public CarMap() { Table("Cars"); Id(car =&gt; car.CarId, mapper =&gt; mapper.Generator(Generators.Identity)); Property(car =&gt; car.Name); Version(car =&gt; car.LastModified, mapper =&gt; { mapper.Generated(VersionGeneration.Always); mapper.Type&lt;BinaryTimestamp&gt;(); }); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload