Let's assume, there is an entity:
class Book
{
public Guid ID { get; set; }
public int Version { get; set; }
public string Author { get; set; }
public string Title { get; set; }
}
The appropriate Fluent NHibernate-mapping:
class BookMapping : ClassMap<Book>
{
public BookMapping()
{
Id(x => x.ID).GeneratedBy.GuidComb();
Version(x => x.Version);
Map(x => x.Author);
Map(x => x.Title);
}
}
I would like to get the incremented value of the Version
property after IStatelessSession.Update()
method call for the Book
instance to perform the related update of another entity (see the comment):
using (var session = sessionFactory.OpenStatelessSession())
{
using (var transaction = session.BeginTransaction())
{
session.Update(book);
// Is it safe to use the value of the book.Version property here?
//
// Just for example:
// bookReference.ID = book.ID;
// bookReference.Version = book.Version; // I would like to have the latest (incremented) version here.
// session.Insert(bookReference);
transaction.Commit();
}
}
Currently the debugging shows it works as desired.
But I have not found the documentation which states that such behavior, i.e. increasing the version value after IStatelessSession.Update()
method call, is guaranteed by NHibernate.
- Could you please provide the reference to the appropriate official documentation? Is there such guarantee?
- Which methods can cause the increment of the
Version
value before theITransaction.Commit()
method is called?