I have a dll that has an entity model that does a particular job. My main application uses that dll but also has it’s own entity model to talk to the DB.
When I save an entity in the main application that triggers a context save of the dll entities, could I wrap them both in a single transaction?
You can, using
TransactionScope.You should be aware, though, that the transaction will be handled by MSDTC rather than at the database level alone.
A better option would be to use the Unit of Work and Repository patterns to ensure that each operation in the chain of events (a single unit of work) used the same context. At the end of the set of operations, you would call SaveChanges a single time which would use a DB transaction.