I need to retrieve random rows from SQL Server database. I am looking for a way to achieve this using LINQ query. Is it possible?
SQL Query: SELECT [Id] FROM [MyTable] ORDER BY NEWID()
What is the equivalent LINQ query for the above SQL?
Thanks in advance.
Make a partial for your data context class and put in the following method:
Now you can compose this into your query and it’ll get translated into calls to the sql newid() function like so: