Skip to content
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

All properties that share a concurrency token must be marked as such #21041

Closed
ajcvickers opened this issue May 25, 2020 · 3 comments · Fixed by #21128
Closed

All properties that share a concurrency token must be marked as such #21041

ajcvickers opened this issue May 25, 2020 · 3 comments · Fixed by #21128
Assignees
Labels
area-model-building closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Milestone

Comments

@ajcvickers
Copy link
Member

ajcvickers commented May 25, 2020

Currently, ModificationCommand.ColumnValuePropagator.TryPropagate sets values into the state manager like this:

((InternalEntityEntry)entry)[property] = _currentValue;

This sets the store-generated value when the property has one, but when it doesn't it just sets the property directly, which means the change cannot be reverted if AcceptChanges is not called. Since this would be a bug, and also because the code above uses the InternalEntityEntry directly, I changed it to:

 entry.SetStoreGeneratedValue(property, _currentValue);

All tests pass except Database_concurrency_token_value_is_updated_for_all_sharing_entities, which throws because one of the properties does not have an appropriate store-generated value slot.

System.InvalidOperationException : The property 'ClientToken' on entity type 'SponsorDetails' cannot be assigned a value generated by the database. Store-generated values can only be assigned to properties configured to use store-generated values.
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.SetStoreGeneratedValue(IProperty property, Object value) in /home/ajcvickers/efcore/src/EFCore/ChangeTracking/Internal/InternalEntityEntry.cs:line 620
   at Microsoft.EntityFrameworkCore.Update.ModificationCommand.ColumnValuePropagator.TryPropagate(IProperty property, IUpdateEntry entry) in /home/ajcvickers/efcore/src/EFCore.Relational/Update/ModificationCommand.cs:line 423
   at Microsoft.EntityFrameworkCore.Update.ModificationCommand.GenerateColumnModifications() in /home/ajcvickers/efcore/src/EFCore.Relational/Update/ModificationCommand.cs:line 281
   at Microsoft.EntityFrameworkCore.Update.ModificationCommand.<>c.<get_ColumnModifications>b__20_0(ModificationCommand command) in /home/ajcvickers/efcore/src/EFCore.Relational/Update/ModificationCommand.cs:line 122
   at Microsoft.EntityFrameworkCore.Internal.NonCapturingLazyInitializer.EnsureInitialized[TParam,TValue](TValue& target, TParam param, Func`2 valueFactory) in /home/ajcvickers/efcore/src/Shared/NonCapturingLazyInitializer.cs:line 24
   at Microsoft.EntityFrameworkCore.Update.ModificationCommand.get_ColumnModifications() in /home/ajcvickers/efcore/src/EFCore.Relational/Update/ModificationCommand.cs:line 121
   at Microsoft.EntityFrameworkCore.Update.Internal.CommandBatchPreparer.<>c.<CreateModificationCommands>b__13_0(ModificationCommand c) in /home/ajcvickers/efcore/src/EFCore.Relational/Update/Internal/CommandBatchPreparer.cs:line 230
   at System.Linq.Enumerable.WhereListIterator`1.MoveNext()
   at System.Collections.Generic.HashSet`1.UnionWith(IEnumerable`1 other)
   at Microsoft.EntityFrameworkCore.Utilities.Multigraph`2.AddVertices(IEnumerable`1 vertices) in /home/ajcvickers/efcore/src/Shared/Multigraph.cs:line 40
   at Microsoft.EntityFrameworkCore.Update.Internal.CommandBatchPreparer.TopologicalSort(IEnumerable`1 commands) in /home/ajcvickers/efcore/src/EFCore.Relational/Update/Internal/CommandBatchPreparer.cs:line 283
   at Microsoft.EntityFrameworkCore.Update.Internal.CommandBatchPreparer.BatchCommands(IList`1 entries, IUpdateAdapter updateAdapter)+MoveNext() in /home/ajcvickers/efcore/src/EFCore.Relational/Update/Internal/CommandBatchPreparer.cs:line 81
   at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.ExecuteAsync(IEnumerable`1 commandBatches, IRelationalConnection connection, CancellationToken cancellationToken) in /home/ajcvickers/efcore/src/EFCore.Relational/Update/Internal/BatchExecutor.cs:line 162
   at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.ExecuteAsync(IEnumerable`1 commandBatches, IRelationalConnection connection, CancellationToken cancellationToken) in /home/ajcvickers/efcore/src/EFCore.Relational/Update/Internal/BatchExecutor.cs:line 180
   at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.ExecuteAsync(IEnumerable`1 commandBatches, IRelationalConnection connection, CancellationToken cancellationToken) in /home/ajcvickers/efcore/src/EFCore.Relational/Update/Internal/BatchExecutor.cs:line 196
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChangesAsync(IList`1 entriesToSave, CancellationToken cancellationToken) in /home/ajcvickers/efcore/src/EFCore/ChangeTracking/Internal/StateManager.cs:line 1071
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChangesAsync(DbContext _, Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken) in /home/ajcvickers/efcore/src/EFCore/ChangeTracking/Internal/StateManager.cs:line 1155
   at Microsoft.EntityFrameworkCore.DbContext.SaveChangesAsync(Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken) in /home/ajcvickers/efcore/src/EFCore/DbContext.cs:line 598
   at Microsoft.EntityFrameworkCore.OptimisticConcurrencySqlServerTest.<>c__DisplayClass2_0.<<Database_concurrency_token_value_is_updated_for_all_sharing_entities>b__0>d.MoveNext() in /home/ajcvickers/efcore/test/EFCore.SqlServer.FunctionalTests/OptimisticConcurrencySqlServerTest.cs:line 72
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.EntityFrameworkCore.ExecutionStrategyExtensions.<>c__7`1.<<ExecuteAsync>b__7_0>d.MoveNext() in /home/ajcvickers/efcore/src/EFCore/Storage/ExecutionStrategyExtensions.cs:line 206
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteImplementationAsync[TState,TResult](Func`4 operation, Func`4 verifySucceeded, TState state, CancellationToken cancellationToken) in /home/ajcvickers/efcore/src/EFCore/Storage/ExecutionStrategy.cs:line 264
   at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteImplementationAsync[TState,TResult](Func`4 operation, Func`4 verifySucceeded, TState state, CancellationToken cancellationToken) in /home/ajcvickers/efcore/src/EFCore/Storage/ExecutionStrategy.cs:line 283
   at Microsoft.EntityFrameworkCore.OptimisticConcurrencySqlServerTest.Database_concurrency_token_value_is_updated_for_all_sharing_entities() in /home/ajcvickers/efcore/test/EFCore.SqlServer.FunctionalTests/OptimisticConcurrencySqlServerTest.cs:line 55
--- End of stack trace from previous location where exception was thrown ---
@lajones
Copy link
Contributor

lajones commented May 30, 2020

Linking to #18063

@lajones lajones added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Jun 3, 2020
@lajones lajones reopened this Jun 3, 2020
@lajones lajones removed the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Jun 3, 2020
@lajones
Copy link
Contributor

lajones commented Jun 3, 2020

Re-opening to remind me to update RelationalModelValidator as well.

@lajones
Copy link
Contributor

lajones commented Jun 4, 2020

Opened #21136 to track the issue above. Closing this issue.

@lajones lajones closed this as completed Jun 4, 2020
@lajones lajones added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Jun 4, 2020
@ajcvickers ajcvickers modified the milestones: 5.0.0, 5.0.0-preview7 Jun 22, 2020
@ajcvickers ajcvickers modified the milestones: 5.0.0-preview7, 5.0.0 Nov 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-model-building closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Projects
None yet
2 participants