开发者

Random linq result

开发者 https://www.devze.com 2022-12-17 17:15 出处:网络
I have this LINQ query: var agnts = (from a in db.agents select new { a.UserId, a.name }).Take(10); How can I get开发者_StackOverflow randomly get 10 records from my agents table?

I have this LINQ query:

var agnts = (from a in db.agents select new { a.UserId, a.name }).Take(10);

How can I get开发者_StackOverflow randomly get 10 records from my agents table?

I have tried:

agnts = agnts.OrderBy(n => Guid.NewGuid());

but this doesn't seem to do anything.

I would appreciate anybody's help on this.

Thanks,

Louis


Then you do

agnts = agnts.OrderBy(n => Guid.NewGuid());

after

var agnts = (from a in db.agents select new { a.UserId, a.name }).Take(10);

agents are already taken. You need to specify OrderBy() before Take()

0

精彩评论

暂无评论...
验证码 换一张
取 消