I am new to NHibernate (and ORMS) and trying to deal with the many different options that it presents. For reference, I use Fluent NHibernate with separate business objects, which, in turn, use DTO exclusively for accessing data. My application architecture should support both windows and web interfaces.
My quandry is one of the common approaches, as there seem to be so many options. My DTO looks something like the sample below. Each DTO has a link to ISession, which is passed to them from BO. They are responsible for their own load and retain:
public class EmployeeDTO...
// Data Properties to be persisted to the database
public virtual int Id { get; private set; }
public virtual string FirstName { get; set; }
public virtual string LastName { get; set; }
public virtual ISession Session { get; set; }
// Save logic
public virtual void Save()
{
var transaction = Session.BeginTransaction();
Session.SaveOrUpdate(this);
transaction.Commit();
}
public virtual void Load(int id)...
First of all:
Is this the right approach - if the DTO can save and load itself?
-:
, /, ISession ISessionFactory , ?
var session = FluentSupport.SessionFactory.OpenSession();
var transaction = Session.BeginTransaction();
Session.SaveOrUpdate(this);
transaction.Commit();
session.Close();
, 3, :)