Getting Random Row via Linq

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
ucelenli
Posts: 5
Joined: Thu 09 Jun 2011 16:19

Getting Random Row via Linq

Post by ucelenli » Tue 05 Nov 2013 13:41

When I use the traditional Guid way for getting a random row from a table i write this;

Code: Select all

var randomUser = db.Users.OrderBy(x => Guid.NewGuid()).FirstOrDefault();
but I get this error. I am using Devart.Data.Postgresql.Entity 7.0.17.0

Code: Select all

The EDM function 'Edm.NewGuid' is not supported by current.
I know I can use "ToList()" but I don't want to convert huge tables into lists for a random row. When will devart support this?

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: Getting Random Row via Linq

Post by Shalex » Fri 08 Nov 2013 17:50

ucelenli wrote:The EDM function 'Edm.NewGuid' is not supported by current.
We will investigate the possibility of supporting the Edm.NewGuid function in dotConnect for PostgreSQL.

As a workaround, please use Devart.Data.PostgreSql.Entity.PgSqlFunctions.Random() for getting a random row from a table.

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: Getting Random Row via Linq

Post by Shalex » Wed 13 Nov 2013 13:05

  • The Entity SQL canonical function NewGuid is supported
  • The config.QueryOptions.NewGuidGenerationMethod configuration option (by default SQL expression is used) is added to provide the possibility to set a way to generate new Guid
We will notify you when the corresponding build of dotConnect for PostgreSQL is available for download.

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: Getting Random Row via Linq

Post by Shalex » Thu 14 Nov 2013 13:16

New build of dotConnect for PostgreSQL 7.1.36 is available for download!
It can be downloaded from http://www.devart.com/dotconnect/postgr ... nload.html (trial version) or from Registered Users' Area (for users with active subscription only).
For more information, please refer to http://forums.devart.com/viewtopic.php?f=3&t=28332.

Post Reply