We are currently refactoring an existing domain model class library to use NHibernate (amongst other things).
One of the things that the old domain objects did was to load reference values from the database in the background - e.g. a 'RiskProfile' object calculates a weight and then 'looks up' a risk profile category (a string) based on this weight directly from the database. Obviously, we don't want to take this approach since separation of the domain and the persistence layers was a key objective in the redesign.
As an alternative, we are currently 'injecting' an in-memory collection of reference data items into the object so that it can do it's own look up. This seems to work OK and the injection can probably be made to be a part of the repository logic.
It did get us thinking though, that it'd be nice if there was a way define a mapping in the HBM file that would load all the rows from a particular reference data table as a collection belonging to another domain object. There is no relationship between the underlying tables, so the normal NHibernate associations don't seem to apply. Is there any way of doing this purely with an NHibernate mapping? Does anybody have any other suggestions for how to deal with reference data of this sort?
|