Does SM begin/commit transactions at the start/end of each web request
Not exactly:
- The transaction is starting when you're accessing current session @ particular web request for the first time.
- The transaction is completed when web request completes.
If so, how can I prevent this?
To prevent creation of transaction at all, you simply shouldn't access current session - i.e. don't use Session.Current
/ Demand()
.
Committing such a transaction earlier is currently impossible without heavy reflection. If you need, we can add this feature.
How can I have an exception thrown when data is attempted to be accessed without creating a transaction manually?
Actually, that's exactly what happens when you deal with newly created Session
. Default SessionOptions
is ServerProfile
- i.e. it throws an exception on any attempt to access the data outside of transaction scope.
But SessionManager
is designed to automatically create the transaction along with the session, and you don't have a chance to prevent this. If this could be prevented, you'd get exactly what you need.
So in your case you need a bit different behavior: SessionManager
must provide just session, but not a session + transaction.
There are two solutions:
- You can fix this by writing your own session manager based on our code.
SessionManager
is part of practices project, so its source code is fully available.
- We can provide an option there allowing to control this.
Possible approach:
// Global option, must be set on app. start
SessionManager.OpenTransaction = false | true;
// default = true
// Or a local one, must be set before accessing
// Session.Current for the first time in
// the current web request.
SessionManager.Current.OpenTransaction = false | true;
// default = null = inherit.
Also, how do we implement transaction reprocessing?
Shortly we'll offer fully automatic integrated solution. For now I can only recommend to ignore this issue.
answered
Feb 11 '11 at 09:56
Alex Yakunin
2971●4●4●12