How do you rollback while using the Transaction attribute?

79 views
Skip to first unread message

Kevin Pang

unread,
Oct 19, 2008, 7:36:48 AM10/19/08
to S#arp Architecture
I'm trying to understand how the Transaction attribute works. As far
as I can tell, it simply wraps an entire controller action in a
transaction. I'm not sure how this would work if I wanted to rollback
one or more transactions within the controller action. It seems as
though if I wanted to support that, I would have to just manually
open / close / rollback the transactions within my controller action.
Is this correct or am I missing something here?

Billy

unread,
Oct 19, 2008, 12:30:40 PM10/19/08
to S#arp Architecture
That's a good question to bring up; currently, as you've noticed,
there's no way to perform this without getting a handle to the current
NHibernate session. All DAO's expose CommitChanges which interacts
with the underlying ISession to perform a context-wide flush of
changes. We could simply add a RollbackTransaction onto the IDAO
signature as well, but this is starting to present a smell of having
non-DAO-specific actions on specific DAOs which have an impact on the
entire data context.

Alternatively, what do you think about CommitChanges, and future non-
DAO-specific DB actions, being encapsulated within a DbContext class
which would be available as a property of all DAOs? An example
invocation would be myDao.DbContext.CommitChanges(). The DbContext
class could then interact with the underlying ISession without having
to expose anything NHibernate specific to the Core and Controllers
layers. RollbackTransaction could then be added to DbContext.

Thoughts on this?

Billy

Brian Chavez

unread,
Oct 19, 2008, 6:51:01 PM10/19/08
to sharp-arc...@googlegroups.com
Hi,

I've used SharpArch since its first inception on CodeProject and followed a
lot of the design philosophy in the Enterprise Sample. Since then, I've
modified and maintained the source constantly improving to fit my needs.

I haven't exactly swapped out the first architecture for the latest one
hosted on here primarily because there are some design issues that I didn't
agree with. One such design issue is this Transaction issue.

In my modified version of SharpArch, I've removed CommitChanges() on the
IDao interface and opted for something like:

using(var x = new TransactionScope())
using(var u = new UnitOfWork()){
//do some stuff,

//possibly with multiple daos calling save
//even on different databases

u.Complete();
}

I prefer having fined grain control over the unit of work and transactions.
I think any addition into SharpArch should not sacrifice explicit control,
IMHO. I've also ripped out the NHSessionManager class and replaced the
implementation to use NHibernate.Context and it's working quite well. I
think, this type of pattern, in my work, lends itself well in distributed
transactions and works well with System.Transactions and MSDTC. ymmv.

-Brian



----------------------------------------------
Brian Chavez
Bit Armory, Inc.
http://www.bitarmory.com

Martin Hornagold

unread,
Oct 20, 2008, 4:10:32 AM10/20/08
to sharp-arc...@googlegroups.com
Billy,

I think moving to a DbContext class is an excellent idea. I don't like the idea of putting it in the DAO. Like Brian I was slightly uneasy with the way transactions are handled in this framework, but I think that this would fix it for my needs.

Regards,

Martin

-----Original Message-----
From: sharp-arc...@googlegroups.com [mailto:sharp-arc...@googlegroups.com] On Behalf Of Billy
Sent: 19 October 2008 17:31
To: S#arp Architecture
Subject: Re: How do you rollback while using the Transaction attribute?


Reply all
Reply to author
Forward
0 new messages