I've read multiple answers to a similar query, but none seem to hit the spot.
Imagine I have a table that contains 10 rows, how do I retrieve 3 random rows from this table using Entity Framework? Not just 1 random row, but 3 random rows - each being different from the other?
Thanks in advance
var threeRandomFoos = foos.OrderBy(x => Guid.NewGuid()).Take(3);
Instead, there is a simpler way,
var threeRandomFoos = foos.OrderBy( x=> SqlFunctions.Rand()).Take(3);
Guid.NewGuid will be little slower in performance, why not use Random specified by SqlFunctions itself?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With