dotnet / efcore

EF Core is a modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations.
https://docs.microsoft.com/ef/
MIT License
13.77k stars 3.18k forks source link

Query: OrderBy(entity) mean different things across relational/non-relational providers #10116

Closed smitpatel closed 4 years ago

smitpatel commented 7 years ago
var query = db.Posts.OrderBy(p => p.Blog).ToList();

At present when there is query which is ordering by an entity type, when evaluated on server converts orderby clause to ordering on PK properties. Since this happens during SqlTranslation, InMemory does not do this. Because of this, if entityType does not implement IComparer then InMemory throws exception whereas relational provider would just work fine. On the other hand, if there IComparer implemented and has different comparison order than keys then relational results would be incorrect.

We should decide on one behavior and make it consistent across relational/non-relational providers.

ajcvickers commented 4 years ago

Remember to document this.

smitpatel commented 4 years ago

Fixed in #20447 Now OrderBy entity to OrderBy entity.PK transformation happens in Nav expansion hence it is consistent across all providers.