4

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.

2
  • 1
    What happens to the guid when the next version is generated? Increase it with one byte on the end? Is Guid.empty unsaved? Commented Nov 9, 2010 at 15:40
  • I imagine you'd create a new Guid? Kind of like timestamp data type. Commented Nov 10, 2010 at 0:45

2 Answers 2

2

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.)

Sign up to request clarification or add additional context in comments.

1 Comment

This works with FluentNHibernate 1.1. I've posted the code on my blog alexlea.me/2010/11/using-guid-as-version-column-in.html. Thanks!
1

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.