Using a Guid Version column in NHibernate
We are working with a legacy database that uses SQL server uniqueidentifier columns for concurrency hence we开发者_运维问答 need to use a Guid as a version column. Any idea how we could achieve this in NHibernate?
We're currently defining our mapping using Fluent NHibernate as a Guid typed property called ConcurrencyId using this snippet
Version(x => x.ConcurrencyId)
This results in the following error when creating a session
System.InvalidCastException : Unable to cast object of type 'NHibernate.Type.GuidType' to type 'NHibernate.Type.IVersionType'.
Any ideas on how this could be done, fluently or otherwise would be appreciated. We're happy to hack the source if it can be made to work.
You could try implementing a custom type implementing NHibernate.UserTypes.IUserVersionType
. (I think this suggestion may pertain to a newer version of NHibernate than you are using.)
Check this...
http://ayende.com/Blog/archive/2009/04/15/nhibernate-mapping-concurrency.aspx
and the docs for the version property
http://www.nhforge.org/doc/nh/en/index.html#mapping-declaration-version
Looks like you can't use a Guid for this. Maybe just map it as a property and handle the version checks yourself.
精彩评论