-
Notifications
You must be signed in to change notification settings - Fork 3.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
SQL Server update does not get values updated by trigger. #6474
Comments
…ow to SQL Server For inserts inner join the INSERTED table instead of reading values directly from it. For updates use the relationat implementation that doesn't use INSERTED table. Fixes #6474
…ow to SQL Server For inserts inner join the INSERTED table instead of reading values directly from it. For updates use the relationat implementation that doesn't use INSERTED table. Fixes #6474
…ow to SQL Server For inserts inner join the INSERTED table instead of reading values directly from it. For updates use the relationat implementation that doesn't use INSERTED table. Fixes #6474
@AndriySvyryd @divega Would you make sure that the case where multiple new child entities are generated using a For example, if I have a hierarchy of tables: Event -> Tournament -> Phase And I add 1 Event, 1 Tournament, 2 Phases at the same time, the following SQL is generated:
Note the insertion for the two When there's a single
|
I'm on 1.0.0 of Microsoft.EntityFramework.Core and Microsoft.EntityFramework.Core.SqlServer.
I have a table with two columns that are updated by an AFTER trigger (not an INSTEAD OF):
__lastModified
(datetimeoffset)__version
(int)There's also a
__rowVersion
column which is of type rowversion.When I call
SaveChanges
, I don't get the values after the trigger fires, I get the values before the trigger is fired.I logged the SQL, and this is what I get:
I notice the OUTPUT statement in there (note, I've also taken a look at issue #1441 but that is an issue with EF not generating an OUTPUT INTO).
The issue is in the documentation for the OUTPUT statement, specifically the section on the INSERTED keyword (emphasis mine):
I've configured the
__lastModified
and__version
columns withValueGeneratedOnAddOrUpdate
so the expectation is that upon return of an UPDATE/INSERT, those values would reflect what is in the database when the operation is complete.As it stands now, the values that come back do not reflect what is in the database and the
DbContext
now stores the incorrect values.The
DbContext
(and by extension, my application) is now inconsistent, and this is a HUGE problem.There's a simple workaround, which is to refetch the entity, and that's what I'm doing now. But given that I'm wasting network bytes bringing something back from the database on a call to
SaveAsync
, why not bring back the correct values?Also disturbing is that the
__rowVersion
column isn't brought back correctly; I now have a rowversion which doesn't exist in the database so if I wanted to try to modify the entity, I can't, because the rowversion for consistency checking will never match.It seems the simple workaround is to start a transaction and just select out the values, like so:
And only select out the values that have been indicated as being refreshed in the database.
The text was updated successfully, but these errors were encountered: