0

How can I order my resultset by NEWID to get a random order?

Philippe Leybaert
  • 168,566
  • 31
  • 210
  • 223
Bjorn Bailleul
  • 3,055
  • 1
  • 20
  • 25

1 Answers1

1

Out of the box, this is not possible, but there's an easy way to embed provider-specific expressions in the OrderedBy() and FilteredBy() expressions.

In your case (assuming you're using SQL Server):

Order.List().OrderedBy("$NEWID()");

What happens here is that every word with a "$" prefix is sent to the database provider "as is" (without the "$" of course). The disadvantage is that this will only work for one provider (so you can't simply switch to MySql and make it work without changing code)

Philippe Leybaert
  • 168,566
  • 31
  • 210
  • 223