In this article Ayende describes how to map a single domain model to multiple physical data models. Is it possible to extend this principle such that the mapping can chosen dynamically?
So for example, imagine we had an entity that could be written to the same physical schema in three ways depending on its current status, and lets assume that regardless of status each entity had a unique identifier.
One solution would be to represent the entity in its different states with three separate classes: one for each mapping. Then the entity could be loaded and in order to change its state the entity could be mapped to a class representing one of its other states开发者_开发百科 and then saved back to the schema, making use of a different mapping.
I was wondering if it is at all possible to have the same entity represented by one class that held a status flag (kind of like a discriminator), and any save to the schema would choose the appropriate mapping based on the value of the status flag.
Hopefully that made sense!
Many thanks.
Even if it were possible, IMHO this is not a good idea. It's basically the same thing asked in this question, and I agree with the answers posted there. Basically, keep it simple, and model your states within a single mapped class.
精彩评论