简体   繁体   中英

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM