0

I'm trying to assign a version column to my table and I want the version to be generated from the DB (getDate()). My mapping looks like that:

Version(x => x.Version).Index("idx_Version").Generated.Always();

but when I'm trying to insert a row, I'm getting this error:

Cannot insert the value NULL into column 'Version'... column does not allow nulls.

I've also tried a different approach and mapped the column as an regular column like this:

Map(x => x.Version).Index("idx_Version").Generated.Always();

but it's generated nulls on that column...

Any ideas?

2
  • I believe this tells NHibernate that the DB will be responsible for filling this column. How is the DB handling it? Did you set a default on the column in the DB? Commented Jun 16, 2013 at 7:36
  • I set a default value of getDate() but it generates it only on insert, not on update. How can I set the value for generated field? Commented Jun 16, 2013 at 11:54

1 Answer 1

2

I guess that you are using MS SQL DB. There are some similar answers:

Summary: implement the trigger on UPDATE to have your column changed even during the UPDATE (not only INSERT with GetDate())

Or (I would suggest this appraoch) use a rowversion which will do for you exactly what you want.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.