linq选择一个随机行 [英] linq select a random row
本文介绍了linq选择一个随机行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在linq-to-sql中有一个名为Quotes的表,该表包含2列:author和quote.如何选择随机行的两列?
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?
推荐答案
Random rand = new Random();
int toSkip = rand.Next(0, context.Quotes.Count);
context.Quotes.Skip(toSkip).Take(1).First();
这篇关于linq选择一个随机行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文