I considered a similar problem with Linq to Sql - initially our solution should use the same connection for each query. Rick Strahl made a series of blog posts worth paying attention to.
In our solution, the DataContext constructor has an overloaded constructor that retrieves the connection from the factory (if there is no connection, the transferred connection is stored in the stream)
public DataContext1(connection) : base (ConnectionFactory.GetConnectionFromContext(connection)) { }
This is similar to working in a WCF script, a factory connection can store / retrieve from the ServiceModel.OperationContext.Items collection and (more importantly) subscribe to the OperationComplete event to close / delete the connection to the stream when all operations are performed.
I found that we also need to expand the connection object so that you can prevent the internal connection from being closed / dipole automatically when the disposable datacontext is placed (for example, after the completion of each workspace).
Now I'm watching scenarios not related to WCF ... TBH is not very. We also do not have an OperationCompleted event trigger that is present in the context of WCF.
source share