question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Translate Guid.NewGuid()

See original GitHub issue

Hi. Today tried to apply .OrderBy(item => Guid.NewGuid()) to get items in random order but as I see Npgsql unable to translate it to Postgres query. In case of MsSQL it works and translates to order by newid() query. I think it will be good to have the same kind feature in Npgsql. Maybe it could be in EF.Functions, I’m not sure…

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:11 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
austindrenskicommented, Nov 13, 2018

the fact that Math.Random() is excluded by the filter means that it’s always server-evaluated, so we can translate it, can’t we?

Ope, you’re right. I had that backwards (again). We should be good to translate it.

0reactions
rojicommented, Nov 13, 2018

@austindrenski great, will look forward to your PR.

Of course you’re right - I meant System.Random(), and you’re right that it’s excluded in the filter. The explanation for that is given in https://github.com/aspnet/EntityFrameworkCore/issues/12672: if it weren’t in the filter, EF Core would evaluate it exactly once and use the same value across all rows. This is because at the moment the concept of “evaluatable” is very coarse, and more nuances are needed (evaluate on server but cache across rows, evaluate on server but don’t cache across rows…).

But to go back to the original question: the fact that Math.Random() is excluded by the filter means that it’s always server-evaluated, so we can translate it, can’t we? After all it’s logically identical to generating a random new UUID…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Guid.ToString Method (System)
Returns a string representation of the value of this instance of the Guid class, according to the provided format specifier and culture-specific format ......
Read more >
Guid.Parse Method (System)
The Parse method trims any leading or trailing white space from input and converts the string representation of a GUID to a Guid...
Read more >
How to Use GUIDs in C#?
In C#, GUIDs can be easily generated using the Guid.NewGuid() method, which returns a new GUID. The following code snippet demonstrates creating ...
Read more >
Understanding the GUID data type in SQL Server
GUID is a 16 byte binary SQL Server data type that is globally unique across tables, databases, and servers. The term GUID stands...
Read more >
GUID in Sql Server
NEWID() NEWID() is a system function that generates a random, globally unique GUID value of type UNIQUEIDENTIFIER. It's based on UuidCreate() ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found