0

I have been facing problem fetching the latest 10 posts made by user. I wrote the following Nhibernate query as follows.

    public IList<T> GetLatest10Posts()
    {
        using (var session = sessionFactory.OpenSession())
        using (var transaction = session.BeginTransaction())
        {
            var queryString = String.Format("SELECT TOP 10 FROM {0} ORDER BY DateUpdated DESC", typeof(T));
            var returnVal = session.CreateQuery(queryString).List<T>();
            transaction.Commit();
            return returnVal;
        }
    }

Exception Thrown

Exception of type 'Antlr.Runtime.NoViableAltException' was thrown. near line 1, column 11

Note: DateUpdated is the column name and is of DateTime type, which is present in all the inheriting entities.

Is there any luck with QueryOver api as I am trying to achieve something like this:

session.QueryOver<T>().Take(10).OrderBy().Desc 
navule
  • 3,212
  • 2
  • 36
  • 54

1 Answers1

2

I wrote a post about the HQL syntax for this last year.

In a nutshell, from {0} order by DateUpdated desc take 10

Diego Mijelshon
  • 52,548
  • 16
  • 116
  • 154