Using DAO's or static methods in Domain Object with nHibernate

Posted by mickyjtwin on Stack Overflow See other posts from Stack Overflow or by mickyjtwin
Published on 2010-06-02T01:41:08Z Indexed on 2010/06/02 1:43 UTC
Read the original article Hit count: 219

Filed under:

I am using nHibernate for the first time, and after alot of reading/researching, plus looking at other projects done with nHibernate, have seen a couple of implementation practices. I am looking for opinions about which would be best to use and why.

Essentially the two methods are as follows:

  1. Using Data Access Objects and a DAO Factory. Example usage:

    INotificationListDAO nListDAO = NHDaoFactory.GetNotificationListDAO(); NotificationList list = nListDAO.GetByListID("");

  2. Use Static methods in the Domain Object. Example usage:

    NotificationList list = NotificationList.GetByListID(""); NHHelper.Session.Get(id);

    NHHelper.Session basically calls the NHibernateSessionManager.Instace.GetSessionFrom("").

While both look similar, it is more to do with best practice. From what I understand, the first option is more so if you are developing enterprise level applications, where my requirements are more for mid-range websites.

© Stack Overflow or respective owner

Related posts about nhibernate