Random List IContentQuery

Topics: General
Jul 29, 2014 at 4:28 AM
I have a problem with Random List
var resultsShowAddress = pListShowAddress.OrderBy(r=> Guid.NewGuid()).Slice(pageSizeShowAddress).ToList();
with the above code, I want after each refresh will get a random list, but i get the error is
Unable to cast object of type 'System.Linq.Expressions.ConstantExpression' to type 'System.Linq.Expressions.UnaryExpression'
Has anybody else experienced this error and can help?
Jul 29, 2014 at 11:15 AM
Unfortunately ContentQuery is quite dump and although the interface seems to allow nothing more than trivial expressions will work in OrderBy() (this is a known issue). You can use HqlQuery (also opened from IContentManager) instead that allows random ordering.