views:

114

answers:

1

I'm moving a project from SubSonic to NHibernate and am using Fluent NHibernate to perform all of our mapping. Our db schema is pretty straight forward and most of our cases appear thus far to be well illustrated by different blog posts and sample code that's available.

One thing that I'm unable to figure out however is the ability to Map a column so that its value is only allowed to be set on the initial INSERT of the data. It's a generated value on our app tier, and once inserted, we don't want to allow it to be updated any further.

I tried the obvious (but wrong)

Map(x => Foo).ReadOnly()

What would be the appropriate function chain to accomplish what I'm after?

+3  A: 

After much experimentation--

Map(u => Foo).Not.Update();

Appears to be doing what I desire--but I'd love if more experienced hands chimed in to confirm that my interpretation of the results is accurate. i'd hate to mark this as the answer and inadvertently send future visitors down the wrong path.

bakasan
That's correct. Insert and Update both default to true, so by saying that your property is "not updatable" implies that it is still insertable. If you wanted update only, you'd do `Not.Insert()`; and if you wanted neither, you'd do `ReadOnly()`.
James Gregory