Can I select a random row using NHibernate's ICriteria
API?
views:
647answers:
2
+4
A:
Just as cundh2o said, it's DBMS-specific. But you can subclass the Order class and define your own custom ordering. For example, for SQL Server:
public class RandomOrder: Order {
public RandomOrder() : base("", true) {}
public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery) {
return new SqlString("newid()");
}
}
Mauricio Scheffer
2009-04-08 23:16:24
2.1.2 compatible: public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery) { return new SqlString("newid()"); }
mxmissile
2010-09-17 21:14:32
@mxmissile: cheers, I updated my answer.
Mauricio Scheffer
2010-09-17 21:34:20