In a finance application, I have a single table called ProductDetails. From this table, I need to first determine a subclass based on a field in the database ( i.e. productType, which can be like BOND or OPTION ). I've set up a discriminator to do this, and it works quite well. I have a ProductAbstract class, and then ProductBond and ProductOption classes which extend it. Works like a charm.
However, for BOND products, I need to further be able to subclass the data based on a different column in the ProductDetails table. For simplicity say we have a bondType field, which can be either CORPORATE, MUNI, or GOVERNMENT. I can't base my first discriminator on this column, because it's only populated for BOND types (not the best data model, but we're stuck with it at this point).
I thought I'd just be able to set up another discriminator at the ProductBond subclass level, but they can't be defined at the subclass level.
Basically, I need to set up a discriminator based on two fields. I've thought of concatenating the two fields into a new database column and basing my discriminator on the new column, but think that's a bit ugly.
I've done some digging, and have seen that I might be able to do this using a <formula> tag, or an EnhancedUserType. I've not been able to find any examples on setting these up. Could someone please get me pointed in the right direction? Alternative approaches and/or example code would of course be very appreciated. Thanks very much.
|