Doing this in NHibernate is a quite simple (for that matter, any ad-hoc SQL). All you need to know is about CreateSQLQuery for the session and returning the UniqueResult.
ISQLQuery sqlQuery = session.CreateSQLQuery("select getdate()"); return sqlQuery.UniqueResult<DateTime>();
If you are interested in a plug and play code example, here it is...
First, a simple NHibernate utility class:
using NHibernate; using NHibernate.Cfg; namespace MyNamespace { /// <summary> /// Author: Kishore Gorjala /// </summary> internal sealed class NHibernateUtility { private static ISessionFactory _factory; #region "Public Properties" /// <summary> /// SessionFactory - Very expensive to create and hence should be singleton /// </summary> internal static ISessionFactory Factory { get { if (_factory == null) { Configuration cfg = new Configuration(); cfg.Configure(); _factory = cfg.BuildSessionFactory(); } return _factory; } } /// <summary> /// Session /// </summary> internal static ISession Session { get { return Factory.OpenSession(); } } #endregion "Public Properties" } }And here is the controller class:
using NHibernate; using System; namespace MyNamespace.DomainControllers { /// <summary> /// HealthCheckController /// Author: Kishore Gorjala /// </summary> public class HealthCheckController { public static DateTime DatabaseTime { get { using (ISession session = DataLayer.NHibernateUtility.Session) { ISQLQuery sqlQuery = session.CreateSQLQuery("select getdate()"); return sqlQuery.UniqueResult<DateTime>(); } } } } }Love coding!