nrdo-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nrdo-list] Re: Proposal: Maintaining a connection across multiple queri


From: Stuart Ballard
Subject: [nrdo-list] Re: Proposal: Maintaining a connection across multiple queries
Date: Wed, 10 May 2006 12:38:01 -0400

After thinking about this a little more I've a couple of revisions to
make to the proposal.

Firstly, I don't think the static GetConnection() method on NrdoScope
should be exposed - I think you should only be able to get at the
connection by creating a scope yourself. This ensures that the
connection remains alive for the right amount of time, and also that
it will be created - and closed - if it doesn't already exist. So if
you need a connection you have to do:

using (NrdoScope scope = new NrdoScope()) {
 IDbConnection conn = scope.GetConnection();
 ... and use the connection here ...
}

(Incidentally, the plan is that under the hood this is exactly what
the generated code will do whenever it needs to access the database).

For similar sorts of reasons, I don't see any particular need for
public access to the current scope (although it must be tracked under
the hood). Anything you might want to do with it can better be done by
creating a new scope, which will ultimately defer to the topmost scope
for the current thread internally anyway. So I'm also removing
NrdoScope.Current and NrdoTransactedScope.Current from the proposed
public API.

There *is* a clear need for the ability to commit, roll back or begin
a transaction within a transacted scope without creating a new
TransactedScope. So the static methods NrdoTransactedScope.Commit(),
.RollBack() and .BeginTransaction() can stay. Just as originally
proposed, Commit and BeginTransaction are no-ops if there isn't a
current transacted scope; RollBack throws an exception.

And since the static methods always do what you want, I think the
answer to the open question of "do we even need nonstatic versions" is
no for these three.

Stuart.
--
http://sab39.dev.netreach.com/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]