tags:

views:

175

answers:

1

My domain entities each have a set of "fixed" properties and a set of "dynamic" properties which can be added at runtime. I handle this by using NHibernate's dynamic-component functionality.

public class Product {
  public virtual Guid Id { get; }
  public virtual string Name { get; set;}
  public virtual IDictionary DynamicComponents { get; }
}

Now I have the following situation

public class Customer {
  public virtual Guid Id { get; }
  public virtual string Type { get; set;}
  public virtual IDictionary DynamicProperties { get; }
}

Where a CustomerType is something like "Online" or "InPerson". Furthermore an Online customer has dynamic properties "Name" and "IPAddress" and an InPerson Customer has dynamic properties "Name" and "Salesman".

Which customer types are available and the extra properties on them are configured in meta-data which is used to generate hbm files on application start.

I could figure out some way to knock this together using an intermediate DTO layer, but is there any support in NHibernate for this scenario? The only difficulty seems to be that all the different "types" of customer map to the same Customer class.

A: 

Maybe a stupid question, but why don't you just use two subclasses of Customer?

Other than that it is not immediately clear to me what it is you want NHibernate to support. Can you clarify what "any support in NHibernate for this scenario" means, what do you want NHibernate to do for you?

Fried Hoeben
They can't be subclasses because they are quasi-dynamic. During run-time I will need to create a new type of Person including rebuilding the mappings. Just like NHibernate allows you to use discriminators to map two sub-classes to 3 tables, I would like a certain mapping to be used only when the discriminator is a certain way. Its awkward, I know but necessary given some very specific constraints on us and unfortunately NH is by far the best ORM quasi-dynamic or otherwise
George Mauer