When using CreateCriteria how do you sort the results in random order?
I have a function that开发者_StackOverflow returns a max number of items that are active.
I would like to be able to make the returned results be sorted in random order.
public IList<Widgets> GetWidgetsToDisplay(int maxToGet)
{
var query = CommonSessionManager.GetSession().CreateCriteria<Widgets>()
.Add(Expression.Eq("IsDeleted", false))
.Add(Expression.Eq("IsActive", true));
return query.SetMaxResults(maxToGet).List<Widgets>();
}
This will be database dependent but have a look here for a sql server order by newid()
solution.
精彩评论