Skip to content

Allow 'unsharing' connection between contexts #30704

@stevendarby

Description

@stevendarby

If a context is created from a pooled factory and borrows a connection & transaction from another context instance, using SetDbConnection and UseTransaction, then I need to ensure that the connection/transaction is 'unborrowed' before disposing the context, otherwise it may be rented from the pool again with the connection still set.

Doing something like context.Database.SetDbConnection(null) throws if the existing connection is still open as because it interprets this as an attempt to dispose the existing connection. However, because the current connection isn't owned by that context, I think it should allow removing the connection without disposing it- or at least provide some other mechanism to do this. (Is there such a mechanism already?)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions