开发者

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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜