I am working on my first NHibernate project, and have the following setup/requirement.
I have 2 projects xx.Data, and xx.Business. In the Data project, this is where my domain classes, mapping files are located. What I am doing is creating an online application, whereby I have a SQL table that stores the ID, modified date, and an XML field which stores the application form details. This is mapped to an EnrolmentApplication domain class.
The xml is deserialised into an ApplicationForm class, which at the moment, is in the xx.Business project. The business project references the Data project.
I started out with my code creating a new ApplicationForm, serialising to xml, then setting the EnrolmentApplicaiton property to the xml string, and saving, which I think is a terrible way of doing things.
I next then thought that I should have a property in the EnrolmentApplication class that has get/set properties to serialise/deserialise the xml property for me, however, I would either have to move the ApplicationForm class into the Data project, or create another class that inherits from EnrolmentApplication, i.e.
using xx.Data;
namespace xx.Business
{
public class EForm : EnrolmentApplication
{
public EForm(Guid applicationID) : base(applicationID)
{}
}
}
My issue with this, is in loading up an EnrolmentApplication from the database. I do not want to do the following:
EnrolmentApplication form = NHibernateSession.Linq<EnrolmentApplication>().SingleOrDefault(x => x.appID);
this.ApplicationXML = form.ApplicationXML;
this.DateModified = form.DatModified;
...
I could make this simple by moving the ApplicationForm class into the Data project, but I would like to keep them separate, as the business class is where the rules for an applicaton form should really reside.