dimanche 30 septembre 2018

Get MULTIPLE random records using Entity Framework?

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:

  1. Generate an array of indexes and use Skip for each. This, however, results in 20 queries (and each is ordered by Id too).

  2. Fetch the list of all Ids and pick randomly into an array and perform a 2nd query for detailed info all selected Ids.

  3. 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