Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
NHibernate 1.0.2.0
Hi.
I am wondering if it is possible to map domain values using NHibernate?
Suppose you have a table with a VARCHAR column named Enabled. This column will always have either the value 'Yes' or the value 'No'.
I would like to map this column to a bool property in C# so that 'Yes' maps to true and 'No' maps to false. Is it possible to specify this mapping?
The only workaround I have been able to find is to do the mapping in code like this:
private string enabled = "No";
public bool Enabled
{
get
{
if (enabled == "No") return false;
if (enabled == "Yes") return true;
throw...
}
set
{
if (value)
enabled = "Yes";
else
enabled = "No";
}
}
I can then map the private enabled field to the Enabled database column. I do not like this approach though as I would prefer to isolate the mapping to the database from the domain object.
Any ideas on how to do this(changing the database schema is not an option)?
Thanks in advance,
Jacob Ilsø