Does anyone out there know how to do the following?
I would like to store values retrieved from the database with NHibernate in a dictionary instead of using a class properties. For example, let's say we have a table Employee with three fields: Id, FirstName, and LastName.
I would like to have a class as follows:
Code:
public class Employee
{
private Int64 _id;
public Int64 Id
{
get { return _id; }
set { _id = value; }
}
private IDictionary<String, Object> _properties;
public IDictionary<String, Object> Properties
{
get { return _properties; }
set { _properties = value; }
}
public void AddProperty(String keyName, Object value)
{
_properties.Add(keyName, value);
}
public Object GetProperty(String keyName)
{
return _properties[keyName];
}
}
Then, I would like for NHibernate, when retrieving/persisting the data, I would like for NHibernate to call methods (or some means) like AddProperty/GetProperty to add the values to the dictionary using the column name as the key.
Is this possible? What I am trying to accomplish is providing a generic class that doesn't need to be compiled everytime a property is added.
Thanks-in-advance.