How to get random row in linqtosql?
Create a view in SQL server for take a random record CREATE VIEW RandomView AS SELECT NEWID() As ID Then create a functin in SQL server CREATE FUNCTION GetNewId ( ) RETURNS uniqueidentifier AS BEGIN RETURN (SELECT ID FROM RandomView) END The view is required because it’s not possible to directly use NEWID in a scalar function. You can then map the GetNewId user-defined function using LINQ to SQL’s Function attribute. Again, see chapter 8 for the details. That’s it! You can now write LINQ queries as usual. Here is an example to pick a random object: var tool = … Click here to continue reading.