Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you're writing large applications then what Kitsune says is the best way.</p> <p>If it's a small set of classes, say less than 5, and not ever going to be a huge enterprise application you could look at this <a href="http://code.google.com/p/nhibernatequeryhelper/" rel="nofollow noreferrer">NHibernate query helper <code>(shameless plug)</code></a> or also the way Codesmith generates its <a href="http://www.codesmithtools.com/video/nhibernate.html" rel="nofollow noreferrer">NHibernate classes</a>.</p> <p>With the first link you simply have your objects holding the data, performing any validation for the business rules: for example having a method called <code>IsValidEmail()</code>. You then use the query manager to perform the <strong>C</strong>reate,<strong>R</strong>ead,<strong>U</strong>pdate,<strong>D</strong>elete tasks, e.g.:</p> <pre><code>NHibernateManager&lt;User&gt; manager = new NHibernateManager&lt;User&gt;(); User name = manager.ReadFirst(); // All items filtered (using OR) IList&lt;User&gt; list = manager.OrList("@Name", "12345", "@Name", "54321"); // Paged list = manager.Page(1,10); </code></pre> <p>The CodeSmith templates are more advanced than this, but work on a similar principle. They expose you to the NHibernate sessions.</p> <p>The ActiveRecord pattern you have done is also perfectly fine and will only ever be scorned by domain driven purists. The only issue is the objects such as User, Contact are then responsible for the NHibernate queries and sessions, but conversely the object is nicely self contained.</p> <p>Which one would you prefer to consume out of 2 (or 3 if you include the Repository pattern) ways of doing it? And ultimately which one is fastest and most appropriate for your project?</p>
 

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