Skip to content

Commit

Permalink
Clarify the trigger convention's usage in the breaking change note (#…
Browse files Browse the repository at this point in the history
…4156)

Closes #4155
  • Loading branch information
roji committed Nov 23, 2022
1 parent 26b1919 commit b3af2c0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion entity-framework/core/providers/sql-server/misc.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ You can let EF Core know that the target table has a trigger; doing so will reve

Note that doing this doesn't actually make EF Core create or manage the trigger in any way - it currently only informs EF Core that triggers are present on the table. As a result, any trigger name can be used, and this can also be used if an unsupported computed column is in use (regardless of triggers).

A model building convention can be used to configure all tables with triggers:
If most or all of your tables have triggers, you can opt out of using the newer, efficient technique for all your model's tables by using the following model building convention:

[!code-csharp[Main](../../../../samples/core/SqlServer/Misc/TriggersContext.cs?name=BlankTriggerAddingConvention)]

Use the convention on your `DbContext` by overriding `ConfigureConventions`:

[!code-csharp[Main](../../../../samples/core/SqlServer/Misc/TriggersContext.cs?name=ConfigureConventions)]

This effectively calls `HasTrigger` on all your model's tables, instead of you having to do it manually for each and every table.
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,16 @@ You can let EF Core know that the target table has a trigger; doing so will reve

Note that doing this doesn't actually make EF Core create or manage the trigger in any way - it currently only informs EF Core that triggers are present on the table. As a result, any trigger name can be used, and this can also be used if an unsupported computed column is in use (regardless of triggers).

A model building convention can be used to configure all tables with triggers:
If most or all of your tables have triggers, you can opt out of using the newer, efficient technique for all your model's tables by using the following model building convention:

[!code-csharp[Main](../../../../samples/core/SqlServer/Misc/TriggersContext.cs?name=BlankTriggerAddingConvention)]

Use the convention on your `DbContext` by overriding `ConfigureConventions`:

[!code-csharp[Main](../../../../samples/core/SqlServer/Misc/TriggersContext.cs?name=ConfigureConventions)]

This effectively calls `HasTrigger` on all your model's tables, instead of you having to do it manually for each and every table.

## Medium-impact changes

<a name="optional-deletes"></a>
Expand Down

0 comments on commit b3af2c0

Please sign in to comment.