문제

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?

도움이 되었습니까?

해결책

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();
    }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top