At compile time, we don't know all the columns that will exist in a particular table. The client my add any columns she likes and our code must read and persists data from these columns.
How can this be done?
Ideally we'd like to have a class with a Hashtable. All the dynamic column values would be stored in the Hashtable. Given a table with the columns Id, Key1, Key2, and Key3, and a class with the following definition, I'd like the values Hashtable to be loaded with each column name as a key associated with the corresponding value found in the table record.
Code:
public class GenericFields
{
private int id;
private Hashtable values;
public int Id
{
get { return id; }
set { id = value; }
}
public Hashtable Values
{
get { return values; }
set { values = value; }
}
}
<class name="GenericFields">
<id name="Id" column="Id"/>
// How to map columns to Hashtable?
</class>
Is this possible? If not, how could I extend NHibernate to do so?
Thanks in advance for your help,
Micah