This answer is not intended to correct exactly what you have, but to get around it.
I propose to encode logic that decides whether to save objects or not at a higher level of the application (in this regard, I consider the EF classes created as low-level objects).
The code that retrieves and stores the data can be implemented in the repository class, that is, in the class that controls your data access logic. So what you use will be this repository class, not EF code. Whether the repository class is internal using EF or something else will not be more important for your application. If you define an interface for your repository class, you can easily replace it with some or technologies for saving and retrieving data.
See here for a Microsoft article on the repository template. This is information from a question here in stackoverflow.
Normally, I would not recommend using classes generated by EF in normal application code. This may be tempting first, but also cause problems later, as in your case.
source share