Is there anyway to completely randomize the result set like sql server's "order by newid()" trick?
2 Answers, 1 is accepted
answered on 15 Sep 2010, 05:09 PM
The randomization in a LINQ query cannot be propagated to the database server with OpenAccess. However, if you retrieve the persistent objects in memory, you can benefit from the LINQ to Objects implementation. You can then order your items by a random number generated with the Random class.
var orderedQuery = query.ToList().OrderBy(x => random.Next());
foreach(var category inorderedQuery)
There is another option which is situationally useful – you can create a view which performs the ordering on the database server side and map it to a persistent type. Each time you retrieve a collection of persistent objects from this view, you will get them in a random order unless you order them explicitly.
I hope this helps. Do not hesitate to contact us if you have more questions.
the Telerik team
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Telerik Public Issue Tracking
system and vote to affect the priority of the items