linq to sql random rows

Discussion of open issues, suggestions and bugs regarding LinqConnect – Devart's LINQ to SQL compatible ORM
Post Reply
actuary
Posts: 3
Joined: Tue 28 Jul 2009 09:34

linq to sql random rows

Post by actuary » Fri 20 Nov 2009 15:42

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

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Tue 24 Nov 2009 13:52

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?

Post Reply