Domanda

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.

È stato utile?

Soluzione

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.

Altri suggerimenti

Using reflection, all you need to get a hold on a class is a fully qualified name . So, store THAT in the database.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top