posts - 81, comments - 262, trackbacks - 0

Randomizing LINQ Queries


I've been using LINQ (with SqlMetal) a lot lately with MVC. I needed to grab a random single record. To my surprise there didn't appear to be a way to do this. I found an interesting post that confirms this and provides a workaround.

 

http://weblogs.asp.net/fmarguerie/archive/2008/01/10/randomizing-linq-to-sql-queries.aspx

 

The workaround is to create a function which returns a newid. As the function can be mapped by SqlMetal the function will be available for sorting server side. Interesting… just a shame the function NEWID() isn't part of DLINQ.


Print | posted on Friday, August 29, 2008 10:37 PM | Filed Under [ Web Programming ]

Powered by:
Powered By Subtext Powered By ASP.NET