Page 1 of 1

linq to sql random rows

Posted: Fri 20 Nov 2009 15:42
by actuary
Hi,

I am trying to select 5 random records from my table using linq to sql, but all attempts have failed. I have created a random function in the .dbml file as

public Guid NewId()

{return Guid.NewGuid();}

and calling my linq as

var _results = (from a in Db.Articles

order by Db.NewId()

select new {a.name, a.DOB }).Distinct().Take(5)



But I get the top 5 rows everytime. Would really appreciate some help here.

Thanks

Posted: Tue 24 Nov 2009 13:52
by AndreyR
Sorry, but I am unable to reproduce the problem using LINQ to Oracle.
The NewId method gives me the "Cannot order by type 'System.Guid'" error.
The code you have provided is not valid for LINQ to SQL usage as well.
Could you please send me a small test project illustrating the error?