Skip to content

Conversation

@alex-kulakov
Copy link
Contributor

There is set of Session events in which changes can be not saved to database because of evens' position in execution.
The user can perform certain changes in them not knowing he will lose the changes.

The events in which changes are prohibited from now on:

  • Events.Persisted (it is triggered after current changes are saved to database, so new changes will be registered to next persist operation and there is a chance it will not happen, for example if persist is triggered by transaction commit);
  • Events.TransactionCommitting (it is triggered AFTER saving changes, there is no chance for next persist operation happen within current transaction);
  • Events.TransactionCommited (current storage transaction is committed and disposed, but the user may open new one within event for some reason and try to make changes).

Talking about Persisted event, it may or may not cause changes loss. If it is manual saving of changes followed by transaction committing or query (in case of session's Server profile) the changes will be saved to the database, but it is basically gambling, and we can't rely on this. It is safer to not allow this to happen.

TransactionCommitting is regularly misinterpreted by users because of global pattern across events - Xxx-ing is before and Xxx-ed is after some action, so some users may think that if they change something in "before" event then it will be saved to database during operation. But TransactionCommitting/TransactionCommitted basically enframe DbTransaction.Commit() operation, saving changes not included.

So, to prevent such mistakes on developing stage and to not allow such design flaws persistent objects changes were prohibited for the described events.

Session.SystemEvents have no such restrictions, we rely on the assumption that if the user uses System events, he acts more carefully, also we use them internally and may have need to perform certain changes of persistent objects within system counterparts of the described events (but not necessary).

# Conflicts:
#	Orm/Xtensive.Orm/Orm/Internals/ChangeRegistries/EntityChangeRegistry.cs
#	Orm/Xtensive.Orm/Orm/Internals/ChangeRegistries/EntitySetChangeRegistry.cs
#	Orm/Xtensive.Orm/Orm/Internals/ChangeRegistries/ReferenceFieldsChangesRegistry.cs
#	Orm/Xtensive.Orm/Orm/Session.cs
#	Orm/Xtensive.Orm/Strings.resx
- new test cases
- correct name for EventInfo fields
- different error message
- method of disabling changes renamed
…nges

there might be scenarios when we might need to change registries even
in controversial scenarios
- no double change of flag field
- explicit init of field value
SystemEvents are out of scope of registration lock
# Conflicts:
#	ChangeLog/7.2.0-dev.txt
@alex-kulakov alex-kulakov merged commit e0d4745 into master Nov 16, 2025
49 checks passed
@alex-kulakov alex-kulakov deleted the master-no-changes-during-persist branch November 16, 2025 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants