linq select a random row

后端 未结 6 1430
悲&欢浪女
悲&欢浪女 2020-12-30 03:05

I have a table called Quotes in linq-to-sql that contains 2 columns: author and quote. How do you select both columns of a random row?

6条回答
  •  不知归路
    2020-12-30 03:50

    Random rand = new Random();
    int toSkip = rand.Next(0, context.Quotes.Count);
    
    context.Quotes.Skip(toSkip).Take(1).First();
    

提交回复
热议问题