NHibernate: Dynamically swapping a single domain model between multiple physical data models

Posted by Nigel on Stack Overflow See other posts from Stack Overflow or by Nigel
Published on 2010-04-28T23:20:55Z Indexed on 2010/04/28 23:27 UTC
Read the original article Hit count: 181

Hi

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.

© Stack Overflow or respective owner

Related posts about nhibernate

Related posts about nhibernate-mapping