Search code examples
c#castle-activerecord

Get current database server date using Castle ActiveRecord


I found the solution, but I don't know how to translate those solution (in NHibernate) to ActiveRecord.


Solution

  • Instead of using a named queries (which I'm not even sure if Castle supports) you could create a native query which is essentially the same thing IMO.

        public static DateTime FindServerDateTime()
        {
            return Helper.GetSession()
                .CreateSQLQuery("select getdate()")
                .UniqueResult<DateTime>();
        }
    

    Replace Helper.GetSession() with whatever function or property you use to fetch the Castle AR session.