OK, we have to calculate eligibility and rates for insanely complicated insurance enrollment data. Policies can be available based on age, employment characteristics, shoe size, etc. People born before 1962 may be excluded except when they live in Texas and have a poodle, etc.
So we can build classes that implement a specification pattern. We can nest and specifications, or specifications, etc. That's great. But now how do we serialize this to the database?
We could dump our c# classes to xml and leave it at that. But that is brittle, but almost impossible to query. Serializing a class to xml and dumping it into a big text field has a definite code smell.
Is there a canonical answer to how to put a nested specification into a database? My Google-fu fails me.
Normalisation, it can be the bane of many a project.
Generally I opt for a pragmatic approach of having individual columns for anything that can be queried (and hence indexed) and dumping all others into a blob in a serialised form.
If this isn't an option for you, you're going to have to introduce redundancy into your table by creating columns that are not applicable to all rows.
I'm yet to come across a one-size fits all approach to this sort of problem.
Using reflection, all you need to get a hold on a class is a fully qualified name . So, store THAT in the database.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With