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.