Quantcast
Viewing all articles
Browse latest Browse all 10

Retrieve random row in Linq in ASP.NET

In MSSQL, we can use NewID function to retrieve a random row. select top 1 * from table order by NewID() How can we implement it with LINQ? There is a Skip function can do the same thing. resultList.Skip(new Random().Next(resultList.Count)).First(); Below is the sample. RandomInLINQ.aspx using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI;... Read more »

Viewing all articles
Browse latest Browse all 10

Trending Articles