From 90717b41e88e03216372cce73b0a427356bb1981 Mon Sep 17 00:00:00 2001 From: AndriySvyryd Date: Tue, 3 Dec 2019 16:42:28 -0800 Subject: [PATCH 1/2] Add breaking change for IMemoryCache Fixes #1943 --- .../ef-core-3.0/breaking-changes.md | 30 ++++++++++++++++--- .../connection-resiliency/retry-logic.md | 2 +- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/entity-framework/core/what-is-new/ef-core-3.0/breaking-changes.md b/entity-framework/core/what-is-new/ef-core-3.0/breaking-changes.md index 746e169ba9..b03ec896c5 100644 --- a/entity-framework/core/what-is-new/ef-core-3.0/breaking-changes.md +++ b/entity-framework/core/what-is-new/ef-core-3.0/breaking-changes.md @@ -1,8 +1,7 @@ --- title: Breaking changes in EF Core 3.0 - EF Core -author: divega -ms.date: 02/19/2019 -ms.assetid: EE2878C9-71F9-4FA5-9BC4-60517C7C9830 +author: ajcvickers +ms.date: 12/03/2019 uid: core/what-is-new/ef-core-3.0/breaking-changes --- @@ -44,6 +43,7 @@ Changes that we expect to only impact database providers are documented under [p | [Throw if multiple compatible backing fields are found](#throw-if-multiple-compatible-backing-fields-are-found) | Low | | [Field-only property names should match the field name](#field-only-property-names-should-match-the-field-name) | Low | | [AddDbContext/AddDbContextPool no longer call AddLogging and AddMemoryCache](#adddbc) | Low | +| [AddEntityFramework* adds IMemoryCache with a size limit](#addentityframework-adds-imemorycache-with-a-size-limit) | Low | | [DbContext.Entry now performs a local DetectChanges](#dbe) | Low | | [String and byte array keys are not client-generated by default](#string-and-byte-array-keys-are-not-client-generated-by-default) | Low | | [ILoggerFactory is now a scoped service](#ilf) | Low | @@ -929,7 +929,7 @@ modelBuilder **Old behavior** -Before EF Core 3.0, calling `AddDbContext` or `AddDbContextPool` would also register logging and memory caching services with D.I through calls to [AddLogging](https://docs.microsoft.com/dotnet/api/microsoft.extensions.dependencyinjection.loggingservicecollectionextensions.addlogging) and [AddMemoryCache](https://docs.microsoft.com/dotnet/api/microsoft.extensions.dependencyinjection.memorycacheservicecollectionextensions.addmemorycache). +Before EF Core 3.0, calling `AddDbContext` or `AddDbContextPool` would also register logging and memory caching services with DI through calls to [AddLogging](https://docs.microsoft.com/dotnet/api/microsoft.extensions.dependencyinjection.loggingservicecollectionextensions.addlogging) and [AddMemoryCache](https://docs.microsoft.com/dotnet/api/microsoft.extensions.dependencyinjection.memorycacheservicecollectionextensions.addmemorycache). **New behavior** @@ -943,6 +943,28 @@ EF Core 3.0 does not require that these services are in the application's DI con If your application needs these services, then register them explicitly with the DI container using [AddLogging](https://docs.microsoft.com/dotnet/api/microsoft.extensions.dependencyinjection.loggingservicecollectionextensions.addlogging) or [AddMemoryCache](https://docs.microsoft.com/dotnet/api/microsoft.extensions.dependencyinjection.memorycacheservicecollectionextensions.addmemorycache). +### AddEntityFramework* adds IMemoryCache with a size limit + +[Tracking Issue #12905](https://github.com/aspnet/EntityFrameworkCore/issues/12905) + +**Old behavior** + +Before EF Core 3.0, calling `AddEntityFramework*` methods would also register memory caching services with DI without a size limit. + +**New behavior** + +Starting with EF Core 3.0, `AddEntityFramework*` will register an IMemoryCache service with a size limit. If any other services added afterwards depend on IMemoryCache they can quickly reach the default limit causing exceptions or degraded performance. + +**Why** + +Using IMemoryCache without a limit could result in uncontrolled memory usage if there is a bug in query caching logic or the queries are generated dynamically. Having a default limit mitigates a potential DoS attack. + +**Mitigations** + +In most cases calling `AddEntityFramework*` is not necessary if `AddDbContext` or `AddDbContextPool` is called as well. Therefore, the best mitigation is to remove the `AddEntityFramework*` call. + +If your application needs these services, then register a IMemoryCache implementation explicitly with the DI container beforehand using [AddMemoryCache](https://docs.microsoft.com/dotnet/api/microsoft.extensions.dependencyinjection.memorycacheservicecollectionextensions.addmemorycache). + ### DbContext.Entry now performs a local DetectChanges diff --git a/entity-framework/ef6/fundamentals/connection-resiliency/retry-logic.md b/entity-framework/ef6/fundamentals/connection-resiliency/retry-logic.md index d7ff540b0b..e15fcd57d6 100644 --- a/entity-framework/ef6/fundamentals/connection-resiliency/retry-logic.md +++ b/entity-framework/ef6/fundamentals/connection-resiliency/retry-logic.md @@ -1,6 +1,6 @@ --- title: "Connection resiliency and retry logic - EF6" -author: ansvyryd +author: AndriySvyryd ms.date: 11/20/2019 ms.assetid: 47d68ac1-927e-4842-ab8c-ed8c8698dff2 --- From ff946a7c086cd9a4986921a4e29b1e7fe43d501b Mon Sep 17 00:00:00 2001 From: AndriySvyryd Date: Tue, 3 Dec 2019 17:18:41 -0800 Subject: [PATCH 2/2] Add breaking change for owned entity queries Fixes #1934 --- .../ef-core-3.0/breaking-changes.md | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/entity-framework/core/what-is-new/ef-core-3.0/breaking-changes.md b/entity-framework/core/what-is-new/ef-core-3.0/breaking-changes.md index b03ec896c5..a218343f5f 100644 --- a/entity-framework/core/what-is-new/ef-core-3.0/breaking-changes.md +++ b/entity-framework/core/what-is-new/ef-core-3.0/breaking-changes.md @@ -36,6 +36,7 @@ Changes that we expect to only impact database providers are documented under [p | [Temporary key values are no longer set onto entity instances](#tkv) | Low | | [Dependent entities sharing the table with the principal are now optional](#de) | Low | | [All entities sharing a table with a concurrency token column have to map it to a property](#aes) | Low | +| [Owned entities cannot be queried without the owner using a tracking query](#owned-query) | Low | | [Inherited properties from unmapped types are now mapped to a single column for all derived types](#ip) | Low | | [The foreign key property convention no longer matches same name as the principal property](#fkp) | Low | | [Database connection is now closed if not used anymore before the TransactionScope has been completed](#dbc) | Low | @@ -612,6 +613,38 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) } ``` + + +### Owned entities cannot be queried without the owner using a tracking query + +[Tracking Issue #18876](https://github.com/aspnet/EntityFrameworkCore/issues/18876) + +**Old behavior** + +Before EF Core 3.0, the owned entities could be queried as any other navigation. + +```csharp +context.People.Select(p => p.Address); +``` + +**New behavior** + +Starting with 3.0, EF Core will throw if a tracking query projects an owned entity without the owner. + +**Why** + +Owned entities cannot be manipulated without the owner, so in the vast majority of cases querying them in this way is an error. + +**Mitigations** + +If the owned entity should be tracked to be modified in any way later then the owner should be included in the query. + +Otherwise add an `AsNoTracking()` call: + +```csharp +context.People.Select(p => p.Address).AsNoTracking(); +``` + ### Inherited properties from unmapped types are now mapped to a single column for all derived types