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

Add more model building breaking changes. #2938

Merged
merged 2 commits into from
Dec 14, 2020
Merged
Changes from 1 commit
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
87 changes: 87 additions & 0 deletions entity-framework/core/what-is-new/ef-core-5.0/breaking-changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ The following API and behavior changes have the potential to break existing appl
| [Cosmos: GetPropertyName and SetPropertyName were renamed](#cosmos-metadata) | Low |
| [Value generators are called when the entity state is changed from Detached to Unchanged, Updated, or Deleted](#non-added-generation) | Low |
| [IMigrationsModelDiffer now uses IRelationalModel](#relational-model) | Low |
| [ToView() is treated differently by migrations](#toview) | Low |
| [ToTable(null) marks the entity type as not mapped to a table](#totable) | Low |
| [Discriminators are read-only](#read-only-discriminators) | Low |
| [Provider-specific EF.Functions methods throw for InMemory provider](#no-client-methods) | Low |
| [IProperty.GetColumnName() is now obsolete](#getcolumnname-obsolete) | Low |
| [IndexBuilder.HasName is now obsolete](#index-obsolete) | Low |
| [A pluralizer is now included for scaffolding reverse engineered models](#pluralizer) | Low |
| [INavigationBase replaces INavigation in some APIs to support skip navigations](#inavigationbase) | Low |
Expand Down Expand Up @@ -335,6 +338,64 @@ var hasDifferences = modelDiffer.HasDifferences(

We are planning to improve this experience in 6.0 ([see #22031](https://github.com/dotnet/efcore/issues/22031))

<a name="toview"></a>

### ToView() is treated differently by migrations

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

#### Old behavior

Calling `ToView(string)` made the migrations ignore the entity type in addition to mapping it to a view.

#### New behavior

Now `ToView(string)` marks the entity type as not mapped to a table in addition to mapping it to a view. This results in the first migration after upgrading to EF Core 5 to try to drop the default table for this entity type as it's not longer ignored.

#### Why

EF Core now allows an entity type to be mapped to both a table and a view simultaneously, so `ToView` is no longer a valid indicator that it should be ignored by migrations.

#### Mitigations

Use the following code to mark the mapped table as excluded from migrations:

```csharp
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<User>().ToTable("UserView", t => t.ExcludeFromMigrations());
}
```

<a name="totable"></a>

### ToTable(null) marks the entity type as not mapped to a table

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

#### Old behavior

`ToTable(null)` would reset the table name to the default.

#### New behavior

`ToTable(null)` now marks the entity type as not mapped to any table.

#### Why

EF Core now allows an entity type to be mapped to both a table and a view simultaneously, so `ToTable(null)` is used to indicate that it isn't mapped to any table.

#### Mitigations

Use the following code to reset the table name to the default if it's not mapped to a view or a DbFunction:

```csharp
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<User>().Metadata.RemoveAnnotation(RelationalAnnotationNames.TableName);
}
```

<a name="read-only-discriminators"></a>

### Discriminators are read-only
Expand Down Expand Up @@ -385,6 +446,32 @@ Provider-specific methods map to a database function. The computation done by th

Since there's no way to mimic behavior of database functions accurately, you should test the queries containing them against same kind of database as in production.

<a name="getcolumnname-obsolete"></a>

### IProperty.GetColumnName() is now obsolete

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

#### Old behavior

`GetColumnName()` returned the name of the column that a property is mapped to.

#### New behavior

`GetColumnName()` still returns of a column that a property is mapped to, but this behavior is now ambiguous since EF Core 5 supports TPT and simultaneous mapping to a view or a function where these mappings could use different column names for the same property.
AndriySvyryd marked this conversation as resolved.
Show resolved Hide resolved

#### Why

We marked this method as obsolete to guide users to a more accurate overload - `IProperty.GetColumnName(StoreObjectIdentifier)`.

#### Mitigations

Use the following code to get the column name for a specific table:

```csharp
var columnName = property.GetColumnName(StoreObjectIdentifier.Table("Users", null)));
```

<a name="index-obsolete"></a>

### IndexBuilder.HasName is now obsolete
Expand Down