I have a repository where I have common methods for adding etc.
And I would like to run 3 methods as a transaction. Is that possible if each of them have “SaveChanges()” in them?
e.g
_somerep.AddCamel("test");
_somerep.AddGoo("test");
_somerep.AddGopher("test");
/Lasse
As long as the repository uses a single entity context and all insertions are handled by a single call to
context.SaveChanges(), they are automatically enrolled in a transaction by Entity Framework.You can also manage transactions via
TransactionScopeas mentioned here (but I wouldn’t suggest it since it requires Microsoft Distributed Transaction Coordinator to be installed…and can cause some weird issues):How to: Manage Transactions in the Entity Framework