Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions entity-framework/core/what-is-new/ef-core-11.0/whatsnew.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,68 @@ For more information on inheritance mapping strategies, see [Inheritance](xref:c

## LINQ and SQL translation

<a name="linq-to-one-join-pruning"></a>

### Better SQL for to-one joins

EF Core 11 generates better SQL when querying with to-one (reference) navigation includes in two ways.

First, when using split queries (`AsSplitQuery()`), EF previously added unnecessary joins to reference navigations in the SQL generated for collection queries. For example, consider the following query:

```csharp
var blogs = context.Blogs
.Include(b => b.BlogType)
.Include(b => b.Posts)
.AsSplitQuery()
.ToList();
```

EF Core previously generated a split query for `Posts` that unnecessarily joined `BlogType`:

```sql
-- Before EF Core 11
SELECT [p].[Id], [p].[BlogId], [p].[Title], [b].[Id], [b0].[Id]
FROM [Blogs] AS [b]
INNER JOIN [BlogType] AS [b0] ON [b].[BlogTypeId] = [b0].[Id]
INNER JOIN [Post] AS [p] ON [b].[Id] = [p].[BlogId]
ORDER BY [b].[Id], [b0].[Id]
```

In EF Core 11, the unneeded join is pruned:

```sql
-- EF Core 11
SELECT [p].[Id], [p].[BlogId], [p].[Title], [b].[Id]
FROM [Blogs] AS [b]
INNER JOIN [Post] AS [p] ON [b].[Id] = [p].[BlogId]
ORDER BY [b].[Id]
```

Second, EF no longer adds redundant keys from reference navigations to `ORDER BY` clauses. Because a reference navigation's key is functionally determined by the parent entity's key (via the foreign key), it does not need to appear separately. For example:

```csharp
var blogs = context.Blogs
.Include(b => b.Owner)
.Include(b => b.Posts)
.ToList();
```

EF Core previously included `[p].[PersonId]` in the `ORDER BY`, even though `[b].[BlogId]` already uniquely identifies the row:

```sql
-- Before EF Core 11
ORDER BY [b].[BlogId], [p].[PersonId]
```

In EF Core 11, the redundant column is omitted:

```sql
-- EF Core 11
ORDER BY [b].[BlogId]
```

Both optimizations can have a significant positive impact on query performance, especially when multiple reference navigations are included.

<a name="linq-maxby-minby"></a>

### MaxBy and MinBy
Expand Down