-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Explanation needed for BlankTriggerAddingConvention
example
#4155
Comments
Here's the text immediately before that code sample:
So what this convention does seems clear - it adds a trigger configuration to all tables which don't have one. IMHO the precise details about the code aren't important within the context of the breaking change note. |
It's very confusing because there is also a bug, the following snippet from the example always calls
And Also it appears to be trying to get all triggers that have no database? wat? Then there's this last bit involving mapping fragments...what are mapping fragments? and why do we have to do what looks like the same thing for these fragments? A little bit more context or explanation I think is reasonable if you expect people to use this as a workaround in production code.
|
That's not a bug - that's exactly what the convention is meant to do. If there are no trigger configurations, it does HasTrigger to add one.
Not no database - no database name. If a table already has a trigger and that trigger has a name, we don't want to create another one. Otherwise we do. |
How is that what the convention is supposed to do? Based on the description in the breaking change explanation - we only need to call |
@pmcilreavy note this sentence right before the convention code:
So you can optionally use this convention to tell EF "all my tables have triggers on them", so that it always generates the slower, more compatible SQL.
That's not true. It only calls HasTrigger if the table has no triggers or configured, or if all configured triggers have no name.
That is the point of this convention.
EF cannot know which tables in the database actually have triggers on them and which don't; you have tell it by configuring that in the model. You can do it on a table-by-table basis by calling HasTrigger yourself (as documented just above in the breaking change note), or if most/all your tables have triggers, you can save yourself the trouble by using this convention, which calls HasTrigger on all tables for you (except for tables where HasTrigger has already been called outside of the convention). |
I think the fact the two issues have been raised by different people about the same thing suggests that further clarification is needed on the article. The lengthy explanation about how we only need to call
This reads as if, the convention can be used to call HasTrigger on all tables that have triggers. i.e. achieving the stated aim of the preceding paragraph. But what it's actually saying is the convention can be used to ensure all tables are opted out. |
@pmcilreavy @dzins I've amended the text to hopefully make this all clearer, can you please take a look? |
👍 looks good. Also, dunno if this should be logged as a separate issue, but I've found I also have to call e.g. a table that has a column with the following constraint... |
Thanks @pmcilreavy
Yep - I've already done this in #4131, but we haven't published that live yet (that should happen very soon). |
There is an example on this page
BlankTriggerAddingConvention
which gives an example of how one should work around the breaking change. Please can you add an explanation about what this code is doing. It's not exactly clear. Seems to be checking for declared triggers on the table, but only triggers that don't have a database? seems a bit strange and warrants further explanation.Document Details
⚠ Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.
The text was updated successfully, but these errors were encountered: