EFCore - Is it possible to ReloadDatabaseValues on Insert? #786
Replies: 2 comments
-
|
The current behavior of I will evaluate adding a separate setting to reload values after the SaveChanges operation, to support scenarios involving computed columns that are generated by the database. |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
Please check #787 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I am aware that the
ReloadDatabaseValuesconfiguration can be used to change the behavior of modifications to entities, but I am wondering if there is a corresponding knob for doing the same on inserts?We have a couple entities with non-key properties that are
ValueGeneratedOnAdd. For example a "stored" computed column (in Postgres) or a column that is set by a database-side trigger. Unless I am missing something, there is currently no way to capture this data upon insert as the EF Core Auditing only reviews the PK/FKs after initial saving.Consider the following C# program:
Project File
Code
The database has a "stored" computed column (only computed on insert, never updated) with an initial value of
8(equivalent to"MyThing".Length). AfterSaveChangesAsyncis called, EF has already re-queried the value back from the database which the console logged message immediately after shows:However the audit doesn't capture it that way and instead reports
inital_name_lengthas having a value of0.But the audit recorded by the subsequent/immediate update shows the field as starting with the appropriate value!
Beta Was this translation helpful? Give feedback.
All reactions