Question

I am using subsonic repository pattern(2.1) for asp.net mvc application.In my application,there are many repositories like categoryRepository,Blogrepository etc.Inside each of this repository i am calling subsonic's DB.Select().From()...ExecuteReader() and then loading domain objects from those reader.

In the controller action i make multiple calls from these repositories for e.g.

List<IBlog> blogs=_blogRepository.GetHottestBlogs();

List<ICategory> categories=_categoryRepository.GetAll();

do i have to implement any unitofwork pattern for this ?.My doubt is that how subsonic performs each operation DB.Update/Insert/Select .Is a TransactionScope is enough for batch update or do i have to use SharedDbConnectionScope to get better performance?

Was it helpful?

Solution

With SubSonic you have to combine TransactionScope and SharedDbConnectionScope. Otherwise every command will use it's own dedicated connection which is disposed after execution, which will lead to an implicit commit (at least for MySQL and Sql Server I think).

Every SubSonic query within a SharedDbConnectionScope will share the same connection, so you can use the TransactioScope.

And you have to use the SharedDbConnectionScope before the TransactionScope, otherwise some providers won't detect that you are executing a Transaction.

using (new SharedDbConnectionScope())
{
    using (TransactionScope ts = new TransactionScope()
    {

        // Do some sh*i ;)
        ts.Complete();
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top