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