What would be the best way using to model the following table structure into the 'pivoted' domain model below, using NHibernate?
Mapping Attribute is trivial; it's really the pivot of rows to properties/virtual columns that I'm unsure about.
Database Structure
Attributes table
Id Name Type
Attr1 Some Attribute 1 Bool
Attr2 Some Attribute 2 Bool
Attr3 Some Attribute 3 Bool
Ad table
Id Name
Ad1 Some ad 1
AdAttributes table
Id AdId AttributeId Value
100 Ad1 Attr1 true
101 Ad1 Attr2 false
102 Ad1 Attr3 true
Desired NHibernate object model
class Attribute{
public int Id {get;set;}
public Type TheType {get;set;}
public string Name {get;set;}
}
class AdAttribute{
public int Id{get;set;}
public Ad Ad{get;set;}
public Attribute Attribute{get;set;}
public bool Value{get;set;}
}
class Ad{
...
class Attributes{
public AdAttribute Attr1{get;set;}
public AdAttribute Attr2{get;set;}
public AdAttribute Attr3{get;set;}
}
Attributes TheAttributes{get; protected set;}
}
The table structure's not set in stone, but the goal is for the Attribute's to not be stored as columns on the Ad. Different Ad type's will have different attributes, but they are not dynamically changing, ie ad type 1 will always have 10 attributes, ad type 2 will always have 5 attributes, etc.
Raw NHibernate HBM answer preferred, but Fluent mappings are ok
IDictionary<string, object>
? NHibernate can serialise objects to 2 columns, but i never tried – Firo