Translate Guid.NewGuid()
See original GitHub issueHi. 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:
- Created 5 years ago
- Reactions:1
- Comments:11 (9 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Ope, you’re right. I had that backwards (again). We should be good to translate it.
@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…