Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ORDER BY NEWID in LINQ and bind to Repeater control

Morning,

I would like to know how to write the following SQL statement in LINQ.

 SELECT TOP 6 * FROM Questions
 ORDER BY NEWID()

I would also like to know, how i could bind this to a asp.net repeater control to display the 6 questions.

Many thanks :)

like image 505
thatuxguy Avatar asked Nov 01 '25 05:11

thatuxguy


1 Answers

The Linq style would be

 Questions.OrderBy(q=>Guid.NewGuid()).Take(6)

then you attach that to a repeater by setting its DataSource property to the above, and calling the DataBind method.

like image 59
podiluska Avatar answered Nov 03 '25 02:11

podiluska



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!