Hi jasonh,
It's actually pretty straight forward. You could create a class like so:
Code:
public class Customer
{
//NHibernate accessors
private int id = 0;
private string name = null;
private string phoneNumber = null;
//Properties
public int Id
{
get { return id; }
set { id = value; }
}
public string Name
{
get { return name; }
set { name = value; }
}
public string PhoneNumber
{
get { return phoneNumber; }
set { phoneNumber = value; }
}
}
Note that the NHibernate accessors are all private and I've provided a set of properties that are public which are in turn referring to the NHibernate accessors. You could add any other logic you wanted to in the getters and setters of course.
This class could be mapped with the following mapping file:
Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" namespace="Framework.Entities" assembly="Framework">
<class name="Customer" table="Customers" lazy="true">
<id name="id" column="CustomerId" unsaved-value="0" access="field">
<generator class="native" />
</id>
<property name="name" column="CustomerName" access="field"/>
<property name="phoneNumber" column="Telephone" access="field" />
</class>
</hibernate-mapping>
You'll notice that the <property> mappings "name" attribute uses the name of the NHibernate accessor in the class (must be matching case!) and the "access" attribute is set to "field" so that it looks for private fields rather than trying to map to the public properties on the class.
Hope this helps,
Symon.