Random Order with Entity Framework

Asked

Viewed 109 times

4

I would like to translate the following SQL statement to an expression lambda:

SELECT TOP 1 * FROM tbPessoa order by NEWID()

What do I put in OrderBy that will be accepted?

var pessoa = contexto.tbPessoa.OrderBy(???).FirstOrDefault()

Note: the table has more than 3000 records, so ideally this should not be done in memory.

1 answer

5


  • It worked. I thought it would be very complicated, and if I had something, it would have to be in memory. I was surprised by the simple solution.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.