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

[Bug] EF7's HasTrigger is not scaffolded for SQL tables with triggers #222

Open
aaron-kruse opened this issue Nov 22, 2022 · 3 comments
Open
Labels
bug Something isn't working

Comments

@aaron-kruse
Copy link

Describe the bug
Scaffolding the DbContext/models with a SQL table that has a trigger does not generate HasTrigger() per a breaking change in EF7. As a result, a DbUpdateException occurs when saving changes that would cause the SQL trigger to fire.

Expected behavior
HasTrigger() should be generated when needed and changes should save without throwing an exception.

To Reproduce

  1. Run scaffolding on a SQL table that has a trigger.
  2. Observe the DbContext generated does not include HasTrigger().
  3. Run code that saves changes to the table with a trigger.
  4. An exception is thrown:

Microsoft.EntityFrameworkCore.DbUpdateException: 'Could not save changes because the target table has database triggers. Please configure your entity type accordingly, see https://aka.ms/efcore-docs-sqlserver-save-changes-and-triggers for more information.'

Additional context
This was originally reported in dotnet/efcore#28185, which was later closed by dotnet/efcore#28253. This was in the 7.0.0 milestone which I believe means the standard tooling is already handling this, but Handlebars is not. I believe this area in HbsCSharpDbContextGenerator.cs corresponds with this area in CSharpDbContextGenerator.cs where the bulk of the changes appear to be (based on the pull request).

I apologize for the lack of a pull request since it feels like I'm about 75% of the way there, but I don't feel like I'm familiar enough with the internal workings of Handlebars to know what else might also need to be updated. Also, the v7.0.0 version of CSharpDbContextGenerator.cs looks completely different from the file originally included in the pull request, which has me a little puzzled (the current file appears to be generated and doesn't have the GenerateEntityType() method where changes were made).

@aaron-kruse aaron-kruse added the bug Something isn't working label Nov 22, 2022
@aaron-kruse
Copy link
Author

For anyone else that might have ran into this, it might also be worth pointing out that the breaking changes documentation has a Mitigations section that includes a pretty simple workaround.

@MisinformedDNA
Copy link

A just ran into this as well. ErikEJ/EFCorePowerTools#1955

@mwmccallum
Copy link
Contributor

Fixed in #239, which is in PR for 8.0.0-beta2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants