ServiceStack Ormlite transaction between services

I'm having issues with a rather complicated save operation inside a ServiceStack service. To simplify the explanation, the service starts the Ormlite transaction and inside it calls another service through the ResolveService:

public ApplicationModel Post(ApplicationModel request)
{
    using (IDbTransaction tr = Db.OpenTransaction())
    {
        using (var cases = ResolveService<CaseService>())
        {
            request.Case = cases.Post(request.Case);
        }
    }
    Db.Save<Application>(request.Application, true);
}

Another service (CaseService) also uses a transaction to execute its logic:

public CaseModel Post(CaseModel request)
{
    using (IDbTransaction tr = Db.OpenTransaction())
    {
        Db.Insert<Case>(request);
        Db.SaveAllReferences<CaseModel>(request);
    }
}

In a similar situation with a higher hierarchy of services that call other services, an error “Timed out” is thrown, and so far I have not been able to solve it, although I have carefully watched SQL Server for deadlocks.

My question is, is this the right way to use / share Ormlite transactions between services, or is there another mechanism?

Thanks in advance.

+4
1

, , , :

public static class DbExtensions
{
    public static void SaveCaseModel(this IDbConnection db,
        CaseModel case)
    {
        db.Insert<Case>(case);
        db.SaveAllReferences<CaseModel>(case);
    }
}

, , :

public ApplicationModel Post(ApplicationModel request)
{
    using (var trans = Db.OpenTransaction())
    {
        Db.SaveCaseModel(request.Case);
        Db.Save<Application>(request.Application, true);
        trans.Commit();
    }
}

public CaseModel Post(CaseModel request)
{
    using (var trans = Db.OpenTransaction())
    {
        Db.SaveCaseModel(request);
        trans.Commit();
    }
}
+3

All Articles