Select N Random Records with Linq

后端 未结 2 1958
醉话见心
醉话见心 2020-12-09 10:13

I have a static table with 20+ records, I would like to select N (N<20) from that table in random manner. What is the best way to do it in the code with LINQ?

2条回答
  •  甜味超标
    2020-12-09 10:55

    Here's the best way:

    var randomUsers = users.OrderBy(x => Guid.NewGuid()).Take(15);
    

提交回复
热议问题