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

TPH + HasTrigger: Potential undocumented breaking change in EFC8 #31627

Closed
Suchiman opened this issue Sep 4, 2023 · 2 comments
Closed

TPH + HasTrigger: Potential undocumented breaking change in EFC8 #31627

Suchiman opened this issue Sep 4, 2023 · 2 comments
Labels
area-model-building closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-bug
Milestone

Comments

@Suchiman
Copy link
Contributor

Suchiman commented Sep 4, 2023

Ask a question

We've just tried our Code with EFC8 and ran into the following issue:

InvalidOperationException: Can't configure a trigger on entity type 'Derived', which is in a TPH hierarchy and isn't the root. Configure the trigger on the TPH root entity type 'Base' instead.

The reason this occurs is due to the BlankTriggerAddingConvention workaround that was described in the EFC7 breaking changes that we've applied https://learn.microsoft.com/en-us/ef/core/what-is-new/ef-core-7.0/breaking-changes#sql-server-tables-with-triggers-or-certain-computed-columns-now-require-special-ef-core-configuration

That workaround calls HasTrigger on every table which seems to be no longer allowed on every table in EFC8.

This change should be documented and a revised workaround provided.

Include provider and version information

EF Core version: 8.0 Preview 7
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 8.0 P7
Operating system: Windows 10
IDE: Visual Studio 2022 17.8P1

@ajcvickers
Copy link
Member

ajcvickers commented Sep 7, 2023

Note from triage: make it a warning and update the guidance to indicate that only the root entity type needs to have triggers defined on it.

@ajcvickers ajcvickers self-assigned this Sep 7, 2023
@ajcvickers ajcvickers added this to the 8.0.0 milestone Sep 7, 2023
@roji
Copy link
Member

roji commented Sep 8, 2023

Note that in EF 8.0 we have the new TableBuilder.UseSqlOutputClause (for SQL Server) and TableBuilder.UseSqlReturningClause (for SQLite) which replaces the "add a blank trigger" technique (#29916).

ajcvickers added a commit that referenced this issue Oct 11, 2023
… type

Part of #31627

### Description

In EF8, we introduced validation that triggers are not defined on a non-base type in a TPH hierarchy. However, our guidance for configuring triggers on every type violates this. Therefore, we are updating the error to a warning, since having the trigger defined doesn't do much harm and so is likely to have been working in the past. We are also updating the guidance for configuring triggers on every type.

### Customer impact

Application that was working in EF7 will throw with EF8.

### How found

Customer reported on preview.

### Regression

Yes.

### Testing

Updated tests.

### Risk

Low.
ajcvickers added a commit to dotnet/EntityFramework.Docs that referenced this issue Oct 11, 2023
@ajcvickers ajcvickers added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Oct 11, 2023
@ajcvickers ajcvickers removed their assignment Aug 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-model-building closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-bug
Projects
None yet
Development

No branches or pull requests

3 participants