Before posting this question, I've seen a lot of examples on NH Versioning and all of those tells me using below code; I can have a versioned-entity using MappingByCode:
Version(e => e.MyVersion, vm => {
vm.Generated(VersionGeneration.Always);
vm.UnsavedValue(0);
});
I expected that assigning MyVersion should be done by SQL Server. So when I call ISession.Save or ISession.SaveOrUpdate; NHProf shows generated sql contains no MyVersion parameter passed to Insert statement (as expected) but query execution goes to be failed because SQL Server doesn't generate it; and result is cannot insert null value into MyVersion column...
error.
My expectation about VersionGeneration.Always is correct? so what's wrong?
I'm using NHibernate 3.3 / SQL Server 2012
VersionGeneration.Always means that NHibernate should expect the database system to generate the version number both on INSERT and on UPDATE.
But you also need to tell SQL Server that it's supposed to generate the number... See for instance http://msdn.microsoft.com/en-us/library/ms182776.aspx.