I have checked this answered question and other articles on Stack Overflow. I prefer the Skip method. However, they are all for single record. Now assume I want to take 20 random records from a table, how can I do that?
I am trying two possibilities:
Generate an array of indexes and use Skip for each. This, however, results in 20 queries (and each is ordered by Id too).
Fetch the list of all Ids and pick randomly into an array and perform a 2nd query for detailed info all selected Ids.
Or just use
OrderByas the other post suggested. I think this can be bad because the entire table is ordered?
Please tell me if there is any better solution.
take(5)so can't you use that astake(20), or I didn't get your exact requirement?Take(5), it would take 5 consecutive records, not random.OrderBy(r => Guid.NewGuid())?OrderBywill mess up the whole table, so I think usingSkipwould be better. When usingSkipI only need to useOrderByon Id instead. (please check the 2nd answer, not the marked answer)