What would be your approach with NHibernate to do the following:
When Comment is inserted into DB, and its property Text is inserted into column Text (due to a mapping), insert into column TextHash a hash of this property value.
It seems trivial if I map TextHash, but how should I do this without mapping it?
I do not need it in the domain model, its a DB-level optimization (I would use computed HashBytes if not for the length limit).
There are some similar questions, such as this one:
Unmapped Columns in NHibernate?
However,
IInterceptorseems like an overkill for a change in a single entity insert. AndEventListenersare less than perfectly documented and also somewhat too complex for a single column.So I have decided on the solution that I see both as most reusable and most local:
Where
StringWithMD5HashUserTypeisICompositeUserTypethat readsTextfrom first column, but writes bothTextand itsHash(I do not add the code ofStringWithMD5HashUserTypebecause it is way too long, but essentially very simple).