views:

139

answers:

1

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

+1  A: 

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