从表中获取3个随机记录 [英] Getting 3 random records from a table

查看:128
本文介绍了从表中获取3个随机记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了一个类似查询的多个答案,但是没有一个似乎没有达到目标。

I've read multiple answers to a similar query, but none seem to hit the spot.

想象一下,我有一个包含10行的表,如何使用Entity Framework从此表中检索3个随机行?不只是1个随机行,而是3个随机行 - 每个行都是不同的?

Imagine I have a table that contains 10 rows, how do I retrieve 3 random rows from this table using Entity Framework? Not just 1 random row, but 3 random rows - each being different from the other?

提前感谢

推荐答案

var threeRandomFoos = foos.OrderBy(x => Guid.NewGuid()).Take(3);

这篇关于从表中获取3个随机记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆