Skip to content

Commit 56ffaaf

Browse files
committed
Document 7.0 SaveChanges incompatibility with some computed columns
Closes #4130
1 parent cb6f750 commit 56ffaaf

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

entity-framework/core/providers/sql-server/misc.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ uid: core/providers/sql-server/misc
77
---
88
# Miscellaneous notes for SQL Server
99

10-
## SaveChanges and database triggers
10+
## SaveChanges, database triggers and unsupported computed columns
1111

12-
Starting with EF Core 7.0, EF Core saves changes to the database with significantly optimized SQL; unfortunately, this technique is not supported on SQL Server if the target table has database triggers. For more information on this SQL Server limitation, see the documentation on the [OUTPUT clause](/sql/t-sql/queries/output-clause-transact-sql).
12+
Starting with EF Core 7.0, EF Core saves changes to the database with significantly optimized SQL; unfortunately, this technique is not supported on SQL Server if the target table has database triggers, or certain kinds of computed columns. For more information on this SQL Server limitation, see the documentation on the [OUTPUT clause](/sql/t-sql/queries/output-clause-transact-sql#remarks).
1313

1414
You can let EF Core know that the target table has a trigger; doing so will revert to the previous, less efficient technique. This can be done by configuring the corresponding entity type as follows:
1515

1616
[!code-csharp[Main](../../../../samples/core/SqlServer/Misc/TriggersContext.cs?name=TriggerConfiguration&highlight=4)]
1717

18-
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.
18+
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).
1919

2020
A model building convention can be used to configure all tables with triggers:
2121

entity-framework/core/what-is-new/ef-core-7.0/breaking-changes.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ EF Core 7.0 targets .NET 6. This means that existing applications that target .N
1616

1717
## Summary
1818

19-
| **Breaking change** | **Impact** |
20-
|:-------------------------------------------------------------------------------------------------------------|------------|
21-
| [`Encrypt` defaults to `true` for SQL Server connections](#encrypt-true) | High |
22-
| [Some warnings will again throw exceptions by default](#warnings-as-errors) | High |
23-
| [SQL Server tables with triggers now require special EF Core configuration](#sqlserver-tables-with-triggers) | High |
24-
| [Orphaned dependents of optional relationships are not automatically deleted](#optional-deletes) | Medium |
25-
| [Cascade delete is configured between tables when using TPT mapping with SQL Server](#tpt-cascade-delete) | Medium |
26-
| [Key properties may need to be configured with a provider value comparer](#provider-value-comparer) | Low |
27-
| [Check constraints and other table facets are now configured on the table](#table-configuration) | Low |
28-
| [Navigations from new entities to deleted entities are not fixed up](#deleted-fixup) | Low |
29-
| [Using `FromSqlRaw` and related methods from the wrong provider throws](#use-the-correct-method) | Low |
19+
| **Breaking change** | **Impact** |
20+
|:---------------------------------------------------------------------------------------------------------------------------------------- | ---------- |
21+
| [`Encrypt` defaults to `true` for SQL Server connections](#encrypt-true) | High |
22+
| [Some warnings will again throw exceptions by default](#warnings-as-errors) | High |
23+
| [SQL Server tables with triggers or certain computed columns now require special EF Core configuration](#sqlserver-tables-with-triggers) | High |
24+
| [Orphaned dependents of optional relationships are not automatically deleted](#optional-deletes) | Medium |
25+
| [Cascade delete is configured between tables when using TPT mapping with SQL Server](#tpt-cascade-delete) | Medium |
26+
| [Key properties may need to be configured with a provider value comparer](#provider-value-comparer) | Low |
27+
| [Check constraints and other table facets are now configured on the table](#table-configuration) | Low |
28+
| [Navigations from new entities to deleted entities are not fixed up](#deleted-fixup) | Low |
29+
| [Using `FromSqlRaw` and related methods from the wrong provider throws](#use-the-correct-method) | Low |
3030

3131
## High-impact changes
3232

@@ -108,7 +108,7 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
108108

109109
<a name="sqlserver-tables-with-triggers"></a>
110110

111-
### SQL Server tables with triggers now require special EF Core configuration
111+
### SQL Server tables with triggers or certain computed columns now require special EF Core configuration
112112

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

@@ -118,19 +118,19 @@ Previous versions of the SQL Server saved changes via a less efficient technique
118118

119119
#### New behavior
120120

121-
By default, EF Core now saves changes via a significantly more efficient technique; unfortunately, this technique is not supported on SQL Server if the target table has database triggers.
121+
By default, EF Core now saves changes via a significantly more efficient technique; unfortunately, this technique is not supported on SQL Server if the target table has database triggers, or certain types of computed columns. See the [SQL Server documentation](/sql/t-sql/queries/output-clause-transact-sql#remarks) for more details.
122122

123123
#### Why
124124

125-
The performance improvements linked to the new method are significant enough that it's important to bring them to users by default. At the same time, we estimate usage of database triggers in EF Core applications to be low enough that the negative breaking change consequences are outweighed by the performance gain.
125+
The performance improvements linked to the new method are significant enough that it's important to bring them to users by default. At the same time, we estimate usage of database triggers or the affected computed columns in EF Core applications to be low enough that the negative breaking change consequences are outweighed by the performance gain.
126126

127127
#### Mitigations
128128

129129
You can let EF Core know that the target table has a trigger; doing so will revert to the previous, less efficient technique. This can be done by configuring the corresponding entity type as follows:
130130

131131
[!code-csharp[Main](../../../../samples/core/SqlServer/Misc/TriggersContext.cs?name=TriggerConfiguration&highlight=4)]
132132

133-
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.
133+
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).
134134

135135
A model building convention can be used to configure all tables with triggers:
136136

0 commit comments

Comments
 (0)