Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding more breaking changes info for EF Core 6.0 #3512

Merged
merged 1 commit into from
Oct 26, 2021
Merged
Show file tree
Hide file tree
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
29 changes: 28 additions & 1 deletion entity-framework/core/what-is-new/ef-core-2.0/upgrade.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Upgrading from previous versions to EF Core 2 - EF Core
description: Instructions and notes for upgrading to Entity Framework Core 2.0
author: ajcvickers
ms.date: 08/13/2017
ms.date: 10/25/2021
uid: core/what-is-new/ef-core-2.0/upgrade
---

Expand Down Expand Up @@ -138,6 +138,33 @@ optionsBuilder.UseInMemoryDatabase("MyDatabase");

This creates/uses a database with the name “MyDatabase”. If `UseInMemoryDatabase` is called again with the same name, then the same in-memory database will be used, allowing it to be shared by multiple context instances.

## In-memory provider 'Include' operation no longer returns results if the included navigation is required but its value is null

When trying to include a required navigation and the included navigation is null, the query no longer returns result for the entity on which the Include operation is applied. To avoid this problem, either provide a value for the required navigation or change the navigation to be optional.

```csharp
public class Person
{
public int Id { get; set; }
public Language NativeLanguage { get; set;} // required navigation
public Person Sibling { get; set; } // optional navigation
}
...
var person = new Person();
context.People.Add(person);
context.SaveChanges();
...

// returns one result
context.People.ToList();

// returns no results because 'NativeLanguage' navigation is required but has not been provided
context.People.Include(p => p.NativeLanguage).ToList();

// returns one result because 'Sibling' navigation is optional so it doesn't have to be provided
context.People.Include(p => p.Sibling).ToList();
```

## Read-only API changes

`IsReadOnlyBeforeSave`, `IsReadOnlyAfterSave`, and `IsStoreGeneratedAlways` have been obsoleted and replaced with [BeforeSaveBehavior](/dotnet/api/microsoft.entityframeworkcore.metadata.iproperty.beforesavebehavior) and [AfterSaveBehavior](/dotnet/api/microsoft.entityframeworkcore.metadata.iproperty.aftersavebehavior). These behaviors apply to any property (not only store-generated properties) and determine how the value of the property should be used when inserting into a database row (`BeforeSaveBehavior`) or when updating an existing database row (`AfterSaveBehavior`).
Expand Down
50 changes: 50 additions & 0 deletions entity-framework/core/what-is-new/ef-core-6.0/breaking-changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ The following API and behavior changes have the potential to break existing appl
| [`DbFunctionBuilder.HasSchema(null)` overrides `[DbFunction(Schema = "schema")]`](#function-schema) | Low |
| [Pre-initialized navigations are overridden by values from database queries](#overwrite-navigations) | Low |
| [Unknown enum string values in the database are not converted to the enum default when queried](#unknown-emums) | Low |
| [DbFunctionBuilder.HasTranslation now provides the function arguments as IReadOnlyList rather than IReadOnlyCollection](#func-args) | Low |
| [Default table mapping is not removed when the entity is mapped to a table-valued function](#tvf-default-mapping) | Low |

\* These changes are of particular interest to authors of database providers and extensions.

Expand Down Expand Up @@ -757,3 +759,51 @@ Converting to the default value can result in database corruption if the entity
#### Mitigations

Ideally, ensure that the database column only contains valid values. Alternately, implement a `ValueConverter` with the old behavior.

<a name="func-args"></a>

### DbFunctionBuilder.HasTranslation now provides the function arguments as IReadOnlyList rather than IReadOnlyCollection

[Tracking Issue #23565](https://github.com/dotnet/efcore/issues/23565)

#### Old behavior

When configuring translation for a user-defined function using `HasTranslation` method, the arguments to the function were provided as `IReadOnlyCollection<SqlExpression>`.

#### New behavior

In EF Core 6.0, the arguments are now provided as `IReadOnlyList<SqlExpression>`.

#### Why

`IReadOnlyList` allows to use indexers, so the arguments are now easier to access.

#### Mitigations

None. `IReadOnlyList` implements `IReadOnlyCollection` interface, so the transition should be straightforward.

<a name="tvf-default-mapping"></a>

### Default table mapping is not removed when the entity is mapped to a table-valued function

[Tracking Issue #23408](https://github.com/dotnet/efcore/issues/23408)

#### Old behavior

When an entity was mapped to a table-valued function, its default mapping to a table was removed.

#### New behavior

In EF Core 6.0, the entity is still mapped to a table using default mapping, even if it's also mapped to table-valued function.

#### Why

Table-valued functions which return entities are often used either as a helper or to encapsulate an operation returning a collection of entities, rather than as a strict replacement of the entire table. This change aims to be more in line with the likely user intention.

#### Mitigations

Mapping to a table can be explicitly disabled in the model configuration:

```csharp
modelBuilder.Entity<MyEntity>().ToTable((string)null);
```