GroupBy element `OrderBy(...).First()`/`MaxBy` over an owned type mapped to its own table fails to translate
Maintainers usually reply within 2 days
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 25/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Stale
- Tech stack
- csharp
- Domain
- backend-api-design, databases
Research direction
Read the GroupBy ordering expansion covered by #38918 and the association tests, especially the OwnedNavigations case; compare it with passing OwnedTableSplitting, OwnedJson and Navigations cases. Reproduce the supplied query with an owned type mapped via ToTable, then trace the translation failure. Done means the query returns posts 2 and 3 and the associated tests pass; linked pull request #39835 is already open.
Written by the indexing model from the issue text.
Description
Ordering the elements of a group by a member of an owned type, to select the first element per group, fails when the owned type is mapped to its own table. #31062 fixed this for table-split owned types in 12.0, but the ToTable case still fails on main.
// Models
class Post
{
public int Id { get; set; }
public int BlogId { get; set; }
public Timestamp Created { get; set; } = null!;
}
class Timestamp
{
public DateTime At { get; set; }
}
// EF setup
modelBuilder.Entity<Post>().OwnsOne(p => p.Created, c => c.ToTable("PostCreated"));
// Data
context.Posts.AddRange(
new Post { Id = 1, BlogId = 1, Created = new Timestamp { At = new DateTime(2026, 1, 1) } },
new Post { Id = 2, BlogId = 1, Created = new Timestamp { At = new DateTime(2026, 1, 3) } },
new Post { Id = 3, BlogId = 2, Created = new Timestamp { At = new DateTime(2026, 1, 2) } });
context.SaveChanges();
// Query: latest post per blog
var latest = context.Posts
.GroupBy(p => p.BlogId)
.Select(g => g.OrderByDescending(p => p.Created.At).First()) // or g.MaxBy(p => p.Created.At)
.ToList();
Expected: posts 2 and 3.
Actual:
InvalidOperationException: Translation of 'EF.Property<Timestamp>(StructuralTypeShaperExpression(
StructuralType: Post
ValueBufferExpression: ProjectionBindingExpression: EmptyProjectionMember
IsNullable: False), "Created")' failed. Either the query source is not an entity type, or the specified property does not exist on the entity type.
Ordering by a property of the entity itself (g.OrderByDescending(p => p.Id).First()) works in both mappings. On main, the association tests show the same split: the query passes for OwnedTableSplitting, OwnedJson and Navigations (a regular reference navigation), and fails only for OwnedNavigations, where the owned types are mapped with ToTable. #38918 expands owned navigations in GroupBy orderings when the owned type is in the same table or in JSON, but not when it needs a join.
- Dominant language
- C#
- Stars
- 14.8k
- Forks
- 3.5k
- Avg merge
- 3d 7h
- Merged PRs (30d)
- 182
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from dotnet/efcore
-
customer-reported
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 2 days
-
SQLite: Polygon.Length translates to GLength, which returns 0Possibly taken @cincuranet claimed this today. Openarea-query area-sqlite
Difficulty 3/5 1-2 days Newbie friendliness 45/100
dotnet/efcore#39826 · 1 assignee ·
Maintainers usually reply within 2 days
-
Migration lock with LockReleaseBehavior.Transaction doesn't prevent concurrent migrations since per-migration transactionsPossibly taken @AndriySvyryd claimed this 1 day ago. Openarea-migrations
dotnet/efcore#39824 · 1 assignee ·
Maintainers usually reply within 2 days
-
Querying a TPC base type with a JSON complex property throwsPossibly taken @cincuranet claimed this 1 day ago. Openarea-query
Difficulty 4/5 3-5 days Newbie friendliness 22/100
dotnet/efcore#39814 · 1 assignee ·
Maintainers usually reply within 2 days
-
Three Cosmos structural-equality tests flaky on Cosmos DB Emulator for WindowsPossibly taken @su-senka claimed this 1 day ago. Open
Difficulty 3/5 Half a day Newbie friendliness 35/100
dotnet/efcore#39809 · 1 comment ·
Maintainers usually reply within 2 days
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
SubtitleEdit/subtitleedit#17247 ·
Maintainers usually reply within 1 day
-
Restore test cleanup fails on Windows when restored files are read-onlyPossibly taken @JamBalaya56562 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
duplicati/duplicati#8046 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
Maintainers usually reply within 1 day
-
Bundles Documentation
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
pyrevitlabs/pyRevit#4285 ·
Maintainers usually reply within 1 day