I'm using a开发者_开发技巧 UserType to maintain a column (Created) in my db.
When saving to db i simply check if the property in question equals DateTime.MinValue, and if so updates it to DateTime.Now (overriding NullSafeSet). This update however, is not immediately reflected by nhibernate, and if i load the object again without evicting it, the value of Created will still be DateTime.MinValue.
Are there any other ways, to get the value NHibernate returns to return the updated value, than using Session.Evict()?
You can (and probably should) do it by hooking into the pre insert and pre update events instead of using IUserType
. Check out this question for more info.
To do what you want to your entity, you could cast evt.Entity
to the interface that supports your field (IHasLastModified
in the example), and set the value.
精彩评论