Random row from Linq to Sql

前端 未结 15 2314
南笙
南笙 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:11

    Using LINQ to SQL in LINQPad as C# statements look like

    IEnumerable customers = this.ExecuteQuery(@"SELECT top 10 * from [Customers] order by newid()");
    customers.Dump();
    

    The generated SQL is

    SELECT top 10 * from [Customers] order by newid()
    

提交回复
热议问题