开发者

How to pull a RANDOM and UNIQUE record from SQL via LINQ

开发者 https://www.devze.com 2022-12-27 19:00 出处:网络
Okay, I found lots of posts on SO about how to pull a RANDOM item from the database when using LINQ. There seems to be a couple of differnet ways to handle this. What I need to do though is pull a RAN

Okay, I found lots of posts on SO about how to pull a RANDOM item from the database when using LINQ. There seems to be a couple of differnet ways to handle this. What I need to do though is pull a RANDOM item from the database that the user has not seen before.

The data I am pulling from the database is very small. Is there any way I can just hit the database once for 1000 records and then randomly scroll through those?

Should I put a cookie on the users system recording the IDs of which items they have seen, pull a random record, check to see if it is seen and if so, pull from the database again? That seems like performance issues just waiting to happen.

I don't expect anyone to c开发者_如何学Code it for me, I am just looking for concepts and pointing in the right direction of how I should go about this.

Need more details? Just let me know!


The usual answer to this question is to create a randomly ordered list and scroll through it linearly. So you'd pull

a, b, c, d, e, f

re-sort it using a randomization algorithm to

b, e, f, a, c, d

and then just do a linear walk.

0

精彩评论

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

关注公众号