Can nHibernate Generate Value For Property?

Nbernate expects that you will define all these rules in your domain classes - for example, in the constructors.

I would say that this should be something that you should specify at the DB level ... If you really want that Nbernate takes care of this, I think you should create an Interceptor that would set the value of that property when it is null at flush-time. Or, you can specify the default value in your entity, by giving the property a default-value in the constructor.

Not a default value. A unique value that's generated when a new entity is saved. I'd forgotten about interceptors.

– Cory Mar 12 '09 at 16:16.

Sorry for the late answer, but I recently ran into the same problem as you. I backtraced a bit in the Nbernate source and seems like I found a solution. You can use the NId namespace for Guid generation.

There's 2 viable options - letting your client generate the Guid or letting the native DB do it. These are the classes you need: NId. NativeGuidGenerator //DB generation NId.

GuidGenerator //Client generation Using the NId. NativeGuidGenerator-class can be accomplished by something like this: public Guid GetNewSessionId() { NId. NativeGuidGenerator guidGen = new NId.

NativeGuidGenerator(); return (Guid)(guidGen. Generate((NEngine. ISessionImplementor)anOpenSession, null)); } Good luck with it :).

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions