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
OrderBy
as 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.
Aucun commentaire:
Enregistrer un commentaire