Random row from Linq to Sql

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

    If you use LINQPad, switch to C# program mode and do this way:

    void Main()
    {
        YourTable.OrderBy(v => Random()).FirstOrDefault.Dump();
    }
    
    [Function(Name = "NEWID", IsComposable = true)]
    public Guid Random()
    {
        throw new NotImplementedException();
    }
    

提交回复
热议问题