Skip to content

Commit

Permalink
Fix to #2436 - Filtered include should also notify users about how it…
Browse files Browse the repository at this point in the history
… interact with tracked entities

adding "caution" block and example

Fixes #2436
  • Loading branch information
maumar committed Jun 15, 2020
1 parent 64c309a commit a9a8519
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions entity-framework/core/querying/related-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ Alternatively, identical operations can be applied for each navigation that is i

[!code-csharp[Main](../../../samples/core/Querying/RelatedData/Sample.cs#MultipleLeafIncludesFiltered2)]

> [!CAUTION]
> In case of tracking queries, results of Filtered Include may be unexpected due to [navigation fixup](tracking.md). All relevant entities that have been querried for previously and have been stored in the Change Tracker will be present in the results of Filtered Include query, even if they don't meet the requirements of the filter. Consider using `NoTracking` queries or re-create the DbContext when using Filtered Include in those situations.
Example:

```csharp
var orders = context.Orders.Where(o => o.Id > 1000).ToList();

// customer entities will have references to all orders where Id > 1000, rathat than > 5000
var filtered = context.Customers.Include(c => c.Orders.Where(o => o.Id > 5000)).ToList();
```

### Include on derived types

You can include related data from navigations defined only on a derived type using `Include` and `ThenInclude`.
Expand Down

0 comments on commit a9a8519

Please sign in to comment.