Reputation: 480
I'm using TransactionScope, and inside it, I'm adding various entities to the context. When an error occurs and the transaction is not commited, these entities are not removed from the context, so if I run the process again, and save the changes, they are added twice to the database. Isn't DbContext aware of TransactionScope transactions? Is there another way to use them?
Upvotes: 0
Views: 79
Reputation: 93424
DbContext is designed to be short lived, for the life of one transaction. If the transaction fails, then you need to destroy the context and start over with a new one.
The context has no cleanup capability (other than as part of disposing of the context), and it's expected that you will create and destroy contexts on each use.
Upvotes: 2