开发者

Get current database server date using Castle ActiveRecord

开发者 https://www.devze.com 2023-02-08 07:59 出处:网络
I found the solution, but I don\'t know how to translate those solution (in NHibern开发者_StackOverflow中文版ate) to ActiveRecord.Instead of using a named queries (which I\'m not even sure if Castle s

I found the solution, but I don't know how to translate those solution (in NHibern开发者_StackOverflow中文版ate) to ActiveRecord.


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.


Just for the record, Castle ActiveRecord does support HQL and SQL named queries (with [HqlNamedQuery] and [SqlNamedQuery] respectively), see this article. For this particular case, I agree with Mike, just use a simple SQL query.

0

精彩评论

暂无评论...
验证码 换一张
取 消