Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translation of NewGuid() #265

Closed
Kazinix opened this issue Apr 27, 2017 · 3 comments
Closed

Translation of NewGuid() #265

Kazinix opened this issue Apr 27, 2017 · 3 comments

Comments

@Kazinix
Copy link

Kazinix commented Apr 27, 2017

Steps to reproduce

I'm using it for getting random records.

_dbContext.Stories
    .Where(s => s.IsPublished)
    .OrderBy(s => Guid.NewGuid())

The issue

Cannot translate to NewGuid() to UUID()

warn: Microsoft.EntityFrameworkCore.Query.Internal.MySqlQueryCompilationContextFactory[8]
      The LINQ expression 'orderby NewGuid() asc' could not be translated and will be evaluated locally.

Further technical details

MySQL version: MariaDB 10.1
Operating system: Windows 8
Pomelo.EntityFrameworkCore.MySql version: 1.1.1

@yukozh
Copy link
Member

yukozh commented Apr 27, 2017

In MySQL order by uuid() will not make your result in a random order. You have to use order by rand()

@yukozh yukozh closed this as completed Apr 27, 2017
@Kazinix
Copy link
Author

Kazinix commented Apr 27, 2017

@kagamine Figured that out just now. BTW, don't you think it's still necessary to add NewGuid for other use?

@sphildreth
Copy link

sphildreth commented Dec 9, 2018

In MySQL order by uuid() will not make your result in a random order. You have to use order by rand()

How does one do this in code? ".OrderBy(x => rand())" ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants