按时间顺序排序(HQL) [英] Order By Rand by Time (HQL)

查看:135
本文介绍了按时间顺序排序(HQL)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用asp.net Mvc 2和NHibernate开发Web应用程序,并且正在页面中分页数据(类别中的产品),但是该数据是随机的,因此,我正在使用HQL语句链接:

I'm developing a web application using asp.net Mvc 2 and NHibernate, and I'm paging data (products in a category) in my page, but this data are random, so, I'm using a HQL statement link this:

string hql = "from Product p where p.Category.Id=:IdCategory order by rand()";

它工作正常,但是当我翻页时,有时同一产品出现在第一,第二等页面中,因为它是由rand()排序的.

It's working fine, but when I page, sometimes the same product appears in the first, second, etc... pages because it's order by rand().

有什么办法可以按时间段(内部时间)确定随机顺序吗?或任何解决方案?

Is there any way to make a random order by fixed by period (time internal) ? Or any solution ?

推荐答案

设置随机数生成器的种子:

Seed the random number generator:

order by rand(123)

我建议使用会话范围的随机数作为种子.这样,该页面不会突然为单个用户重新排序,但仍会为每个用户不同地对其排序.

I would suggest using a session-scoped random number as your seed. That way, the page doesn't suddenly re-sort for a single user, but it's still be sorted differently for every user.

这篇关于按时间顺序排序(HQL)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆