You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: entity-framework/core/what-is-new/ef-core-11.0/whatsnew.md
+62Lines changed: 62 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -79,6 +79,68 @@ For more information on inheritance mapping strategies, see [Inheritance](xref:c
79
79
80
80
## LINQ and SQL translation
81
81
82
+
<aname="linq-to-one-join-pruning"></a>
83
+
84
+
### Better SQL for to-one joins
85
+
86
+
EF Core 11 generates better SQL when querying with to-one (reference) navigation includes in two ways.
87
+
88
+
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:
89
+
90
+
```csharp
91
+
varblogs=context.Blogs
92
+
.Include(b=>b.BlogType)
93
+
.Include(b=>b.Posts)
94
+
.AsSplitQuery()
95
+
.ToList();
96
+
```
97
+
98
+
EF Core previously generated a split query for `Posts` that unnecessarily joined `BlogType`:
INNER JOIN [Post] AS [p] ON [b].[Id] = [p].[BlogId]
116
+
ORDER BY [b].[Id]
117
+
```
118
+
119
+
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:
120
+
121
+
```csharp
122
+
varblogs=context.Blogs
123
+
.Include(b=>b.Owner)
124
+
.Include(b=>b.Posts)
125
+
.ToList();
126
+
```
127
+
128
+
EF Core previously included `[p].[PersonId]` in the `ORDER BY`, even though `[b].[BlogId]` already uniquely identifies the row:
129
+
130
+
```sql
131
+
-- Before EF Core 11
132
+
ORDER BY [b].[BlogId], [p].[PersonId]
133
+
```
134
+
135
+
In EF Core 11, the redundant column is omitted:
136
+
137
+
```sql
138
+
-- EF Core 11
139
+
ORDER BY [b].[BlogId]
140
+
```
141
+
142
+
Both optimizations can have a significant positive impact on query performance, especially when multiple reference navigations are included.
0 commit comments