NHibernate: Mapping different dynamic components based on a discriminator
Posted
by George Mauer
on Stack Overflow
See other posts from Stack Overflow
or by George Mauer
Published on 2010-04-15T20:19:52Z
Indexed on
2010/04/15
20:23 UTC
Read the original article
Hit count: 737
nhibernate
|dynamic-entities
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.
© Stack Overflow or respective owner