What is the best (and fastest) way to retreive random rows using Linq to SQL with unique data / no duplicate record? oh i preffer to do it in 1 statement, does it possible? i found this relevant question but i don't think that this approach resulting unique records.
i have tried this so far :
//first approach
AirAsiaDataContext LinqDataCtx = new AirAsiaDataContext();
var tes = (from u in LinqDataCtx.users.AsEnumerable()
orderby Guid.NewGuid()
select u).Take(5);
//second approach
var usr = from u in LinqDataCtx.users
select u;
int count = usr.Count(); // 1st round-trip
int index = new Random().Next(count);
List<user> tes2 = new List<user>();
for (int i = 0; i < 5; i++)
{
tes2.Add(usr.Skip(index).FirstOrDefault()); // 2nd round-trip
}
as you can see above, i have tried 2 solution, it works, but above codes did not resulting unique records, there are chances for duplicate.