Get Random Records using LINQ in .Net

Last Reply 23 days ago By Andrea

Posted 23 days ago

hello,

i have this linQ query, how to get 6 random records on each page load

in sql we use to do order by new guid()

var q = (from p in db.Profiles
         where p.ProfileStatus == "Completed" && p.UserName != this.Page.User.Identity.Name
         select p).Distinct().Take(6).ToList();

 

 

You are viewing reply posted by: Andrea 23 days ago.
Posted 23 days ago
Hi @nauna,
Please try the following

Get Random Records from Generic List (List) using LINQ in C# .Net

It might help you.

Cheers Andrea.