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/modeling/inheritance.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -31,7 +31,7 @@ By default, EF maps the inheritance using the *table-per-hierarchy* (TPH) patter
31
31
32
32
The model above is mapped to the following database schema (note the implicitly-created `Discriminator` column, which identifies which type of `Blog` is stored in each row).
33
33
34
-

34
+

35
35
36
36
You can configure the name and type of the discriminator column and the values that are used to identify each type in the hierarchy:
The model above is mapped to the following database schema:
35
+
36
+

37
+
34
38
See the [full sample project](https://github.com/dotnet/EntityFramework.Docs/tree/master/samples/core/Modeling/OwnedEntities) for more context.
35
39
36
40
> [!TIP]
@@ -63,6 +67,10 @@ To configure a different primary key call `HasKey`.
The model above is mapped to the following database schema:
71
+
72
+

73
+
66
74
## Mapping owned types with table splitting
67
75
68
76
When using relational databases, by default reference owned types are mapped to the same table as the owner. This requires splitting the table in two: some columns will be used to store the data of the owner, and some columns will be used to store data of the owned entity. This is a common feature known as [table splitting](xref:core/modeling/table-splitting).
@@ -114,6 +122,10 @@ It is also possible to achieve this result using `OwnedAttribute` on both `Order
114
122
115
123
In addition, notice the `Navigation` call. In EFCore 5.0, navigation properties to owned types can be further configured [as for non-owned navigation properties](xref:core/modeling/relationships#configuring-navigation-properties).
116
124
125
+
The model above is mapped to the following database schema:
126
+
127
+

128
+
117
129
## Storing owned types in separate tables
118
130
119
131
Also unlike EF6 complex types, owned types can be stored in a separate table from the owner. In order to override the convention that maps an owned type to the same table as the owner, you can simply call `ToTable` and provide a different table name. The following example will map `OrderDetails` and its two addresses to a separate table from `DetailedOrder`:
Copy file name to clipboardExpand all lines: entity-framework/core/querying/complex-query-operators.md
+11-1
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,7 @@ Language Integrated Query (LINQ) contains many complex operators, which combine
14
14
15
15
## Join
16
16
17
-
The LINQ Join operator allows you to connect two data sources based on the key selector for each source, generating a tuple of values when the key matches. It naturally translates to `INNER JOIN` on relational databases. While the LINQ Join has outer and inner key selectors, the database requires a single join condition. So EF Core generates a join condition by comparing the outer key selector to the inner key selector for equality. Further, if the key selectors are anonymous types, EF Core generates a join condition to compare equality component wise.
17
+
The LINQ Join operator allows you to connect two data sources based on the key selector for each source, generating a tuple of values when the key matches. It naturally translates to `INNER JOIN` on relational databases. While the LINQ Join has outer and inner key selectors, the database requires a single join condition. So EF Core generates a join condition by comparing the outer key selector to the inner key selector for equality.
INNER JOIN [Person] AS [p] ON ([p0].[PersonPhotoId] = [p].[PhotoId] AND ([p0].[Caption] = N'SN'))
35
+
```
36
+
27
37
## GroupJoin
28
38
29
39
The LINQ GroupJoin operator allows you to connect two data sources similar to Join, but it creates a group of inner values for matching outer elements. Executing a query like the following example generates a result of `Blog` & `IEnumerable<Post>`. Since databases (especially relational databases) don't have a way to represent a collection of client-side objects, GroupJoin doesn't translate to the server in many cases. It requires you to get all of the data from the server to do GroupJoin without a special selector (first query below). But if the selector is limiting data being selected then fetching all of the data from the server may cause performance issues (second query below). That's why EF Core doesn't translate GroupJoin.
Copy file name to clipboardExpand all lines: entity-framework/core/querying/filters.md
+17
Original file line number
Diff line number
Diff line change
@@ -41,6 +41,23 @@ The predicate expressions passed to the `HasQueryFilter` calls will now automati
41
41
42
42
You can also use navigations in defining global query filters. Using navigations in query filter will cause query filters to be applied recursively. When EF Core expands navigations used in query filters, it will also apply query filters defined on referenced entities.
43
43
44
+
To illustrate this configure query filters in `OnModelCreating` in the following way:
This query produces the following SQL, which applies query filters defined for both `Blog` and `Post` entities:
51
+
52
+
```sql
53
+
SELECT [b].[BlogId], [b].[Name], [b].[Url]
54
+
FROM [Blogs] AS [b]
55
+
WHERE (
56
+
SELECTCOUNT(*)
57
+
FROM [Posts] AS [p]
58
+
WHERE ([p].[Title] LIKE N'%fish%') AND ([b].[BlogId] = [p].[BlogId])) >0
59
+
```
60
+
44
61
> [!NOTE]
45
62
> Currently EF Core does not detect cycles in global query filter definitions, so you should be careful when defining them. If specified incorrectly, cycles could lead to infinite loops during query translation.
Copy file name to clipboardExpand all lines: entity-framework/core/querying/related-data/eager.md
+4-1
Original file line number
Diff line number
Diff line change
@@ -46,7 +46,7 @@ You may want to include multiple related entities for one of the entities that i
46
46
> [!NOTE]
47
47
> This feature is introduced in EF Core 5.0.
48
48
49
-
When applying Include to load related data, you can apply certain enumerable operations on the included collection navigation, which allows for filtering and sorting of the results.
49
+
When applying Include to load related data, you can add certain enumerable operations to the included collection navigation, which allows for filtering and sorting of the results.
> In case of tracking queries, the navigation on which filtered include was applied is considered to be loaded. This means that EF Core will not attempt to re-load it's values using [explicit loading](xref:core/querying/related-data/explicit) or [lazy loading](xref:core/querying/related-data/lazy), even though some elements could still be missing.
79
+
77
80
## Include on derived types
78
81
79
82
You can include related data from navigation defined only on a derived type using `Include` and `ThenInclude`.
Copy file name to clipboardExpand all lines: entity-framework/core/what-is-new/ef-core-5.0/breaking-changes.md
+89
Original file line number
Diff line number
Diff line change
@@ -29,6 +29,8 @@ The following API and behavior changes have the potential to break existing appl
29
29
|[IndexBuilder.HasName is now obsolete](#index-obsolete)| Low |
30
30
|[A pluarlizer is now included for scaffolding reverse engineered models](#pluralizer)| Low |
31
31
|[INavigationBase replaces INavigation in some APIs to support skip navigations](#inavigationbase)| Low |
32
+
|[Some queries with correlated collection that also use `Distinct` or `GroupBy` are no longer supported](#collection-distinct-groupby)| Low |
33
+
|[Using a collection of Queryable type in projection is not supported](#queryable-projection)| Low |
32
34
33
35
## Medium-impact changes
34
36
@@ -450,3 +452,90 @@ Most of the functionality between normal and skip navigations is the same. Howev
450
452
#### Mitigations
451
453
452
454
Inmanycasesapplicationscanswitch to using the new base interface with no other changes. However, in cases where the navigation is used to access foreign key properties, application code should either be constrained to only normal navigations, or updated to do the appropriate thing for both normal and skip navigations.
455
+
456
+
<a name="collection-distinct-groupby"></a>
457
+
458
+
### Some queries with correlated collection that also use `Distinct` or `GroupBy` are no longer supported
Forcorrelatedcollectionscenariosweneedtoknowentity'sprimarykeyinordertoassigncollectionentitiestothecorrectparent. Wheninnercollectiondoesn'tuse `GroupBy` or `Distinct`, themissingprimarykeycansimplybeaddedtotheprojection. Howeverincaseof `GroupBy` and `Distinct` itcan't be done because it would change the result of `GroupBy` or `Distinct` operation.
493
+
494
+
**Mitigations**
495
+
496
+
Rewritethequerytonotuse `GroupBy` or `Distinct` operationsontheinnercollection, andperformtheseoperationsontheclientinstead.
497
+
498
+
```csharp
499
+
context.Parents
500
+
.Select(p=>p.Children.Select(c=>c.School))
501
+
.ToList()
502
+
.Select(x=>x.GroupBy(c=>c).Select(g=>g.Key))
503
+
```
504
+
505
+
```csharp
506
+
context.Parents
507
+
.Select(p=>p.Children.Select(c=>c.School))
508
+
.ToList()
509
+
.Select(x=>x.Distinct())
510
+
```
511
+
512
+
<aname="queryable-projection"></a>
513
+
514
+
### Using a collection of Queryable type in projection is not supported
Console.WriteLine("Blogs without any Posts are also filtered out. Posts must contain 'fish' in title.");
322
+
Console.WriteLine("Filters are applied recursively, so Blogs that do have Posts, but those Posts don't contain 'fish' in the title will also be filtered out.");
0 commit comments