Note that there are some explanatory texts on larger screens.

plurals
  1. POBest approach for building NHibernate DTO's
    primarykey
    data
    text
    <p>I'm new to NHibernate (and ORMS) and trying to come to grips with the myriad of different options it presents. For reference, I'm using Fluent NHibernate with seperate business objects which in turn use DTO's purely for data access. My application architecture must support both windows and web "front ends".</p> <p>My quandry is one of general approach as there seem to be so many options. My DTO's look something like the sample below. Each DTO has a reference to an ISession which is passed to them from the BO. They are responsible for their own load and save:</p> <pre><code>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(); } // Load logic public virtual void Load(int id)... </code></pre> <p><strong>First of all:</strong> Is this the correct approach to take - should the DTO have the ability to save and load itself?</p> <p><strong>Secondly:</strong> Regardless of where the save/load code lies, should you use the same ISession for the lifetime or an object, or should they have a ref to the ISessionFactory and open a new session every time database interaction is required?</p> <pre><code> // Open a new session every time I interact with the repository var session = FluentSupport.SessionFactory.OpenSession(); var transaction = Session.BeginTransaction(); Session.SaveOrUpdate(this); transaction.Commit(); session.Close(); // Close the session when I'm done </code></pre> <p>Of course there's always option 3, none of the above :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload