Skip to content

Commit

Permalink
Adding more breaking changes info for EF Core 6.0
Browse files Browse the repository at this point in the history
Fixes #3486
Fixes #3488
Fixes #3490
  • Loading branch information
maumar committed Oct 26, 2021
1 parent cebe7f3 commit 9768635
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
27 changes: 27 additions & 0 deletions entity-framework/core/what-is-new/ef-core-2.0/upgrade.md
Original file line number Diff line number Diff line change
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 will no longer return 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 will no longer return result for the entity on which Include operation is applied. To avoid this problem, either provide value for required navigation or change the navigation to 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 defining DbFunction translation using `HasTranslation` method, the arguments to the function were provided as `IReadOnlyCollection<SqlExpression>`.

#### New behavior

In EF Core 6.0 the arguments are 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 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 function returning entity is often used 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);
```

0 comments on commit 9768635

Please sign in to comment.