Skip to content

Commit 9768635

Browse files
committed
Adding more breaking changes info for EF Core 6.0
Fixes #3486 Fixes #3488 Fixes #3490
1 parent cebe7f3 commit 9768635

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

entity-framework/core/what-is-new/ef-core-2.0/upgrade.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,33 @@ optionsBuilder.UseInMemoryDatabase("MyDatabase");
138138

139139
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.
140140

141+
## In-memory provider 'Include' operation will no longer return results if the included navigation is required but its value is null
142+
143+
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.
144+
145+
```csharp
146+
public class Person
147+
{
148+
public int Id { get; set; }
149+
public Language NativeLanguage { get; set;} // required navigation
150+
public Person Sibling { get; set; } // optional navigation
151+
}
152+
...
153+
var person = new Person();
154+
context.People.Add(person);
155+
context.SaveChanges();
156+
...
157+
158+
// returns one result
159+
context.People.ToList();
160+
161+
// returns no results because 'NativeLanguage' navigation is required but has not been provided
162+
context.People.Include(p => p.NativeLanguage).ToList();
163+
164+
// returns one result because 'Sibling' navigation is optional so it doesn't have to be provided
165+
context.People.Include(p => p.Sibling).ToList();
166+
```
167+
141168
## Read-only API changes
142169

143170
`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`).

entity-framework/core/what-is-new/ef-core-6.0/breaking-changes.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ The following API and behavior changes have the potential to break existing appl
3535
| [`DbFunctionBuilder.HasSchema(null)` overrides `[DbFunction(Schema = "schema")]`](#function-schema) | Low |
3636
| [Pre-initialized navigations are overridden by values from database queries](#overwrite-navigations) | Low |
3737
| [Unknown enum string values in the database are not converted to the enum default when queried](#unknown-emums) | Low |
38+
| [DbFunctionBuilder.HasTranslation now provides the function arguments as IReadOnlyList rather than IReadOnlyCollection](#func-args) | Low |
39+
| [Default table mapping is not removed when the entity is mapped to a table-valued function](#tvf-default-mapping) | Low |
3840

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

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

759761
Ideally, ensure that the database column only contains valid values. Alternately, implement a `ValueConverter` with the old behavior.
762+
763+
<a name="func-args"></a>
764+
765+
### DbFunctionBuilder.HasTranslation now provides the function arguments as IReadOnlyList rather than IReadOnlyCollection
766+
767+
[Tracking Issue #23565](https://github.com/dotnet/efcore/issues/23565)
768+
769+
#### Old behavior
770+
771+
When defining DbFunction translation using `HasTranslation` method, the arguments to the function were provided as `IReadOnlyCollection<SqlExpression>`.
772+
773+
#### New behavior
774+
775+
In EF Core 6.0 the arguments are provided as `IReadOnlyList<SqlExpression>`.
776+
777+
#### Why
778+
779+
`IReadOnlyList` allows to use indexers, so the arguments are now easier to access.
780+
781+
#### Mitigations
782+
783+
None. `IReadOnlyList` implements `IReadOnlyCollection` interface, so the transition should be straightforward.
784+
785+
<a name="tvf-default-mapping"></a>
786+
787+
### Default table mapping is not removed when the entity is mapped to a table-valued function
788+
789+
[Tracking Issue #23408](https://github.com/dotnet/efcore/issues/23408)
790+
791+
#### Old behavior
792+
793+
When entity was mapped to a table-valued function, its default mapping to a table was removed.
794+
795+
#### New behavior
796+
797+
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.
798+
799+
#### Why
800+
801+
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.
802+
803+
#### Mitigations
804+
805+
Mapping to a table can be explicitly disabled in the model configuration:
806+
807+
```csharp
808+
modelBuilder.Entity<MyEntity>().ToTable((string)null);
809+
```

0 commit comments

Comments
 (0)