Random row from Linq to Sql

前端 未结 15 2561
南笙
南笙 2020-11-22 05:39

What is the best (and fastest) way to retrieve a random row using Linq to SQL when I have a condition, e.g. some field must be true?

15条回答
  •  不知归路
    2020-11-22 06:13

    if you want to get e.g. var count = 16 random rows from table, you can write

    var rows = Table.OrderBy(t => Guid.NewGuid())
                            .Take(count);
    

    here I used E.F, and the Table is a Dbset

提交回复
热议问题