JordanMarr / SqlHydra

SqlHydra is a suite of NuGet packages for working with databases in F# including code generation tools and query expressions.
MIT License
223 stars 22 forks source link

Connection disposed when disposing QueryContext #9

Closed MargaretKrutikova closed 2 years ago

MargaretKrutikova commented 2 years ago

QueryContext disposes database connection here when it is disposed, and it also takes care of transactions. Do we really want to dispose the connection once a transaction disposes? Our understanding of QueryContext is that it is a light-weight object that is created for every db operation, with transaction in case it is necessary, but it will be quite expensive to create a new db connection for each query context. Does it make sense to either remove connection disposal or maybe even require the connection to be send in each method instead? That way it is the consumer's responsibility to make sure the connection is properly disposed.

JordanMarr commented 2 years ago

Npgsql and the other ADO.NET providers implement connection pooling so that connections with the same connection string are kept in a pool after you close them to prevent performance degradation. So no optimization should be necessary.

MargaretKrutikova commented 2 years ago

Yes, we investigated this deeper today and came to the same conclusion. Thanks for the response!