views:

164

answers:

1

I'm trying to do the most simple thing and apply a transaction to the CreatePortal method.

If I'm using TransactionScope - It promotes to DTC for some unknown reason - BAD.

using (var ts = new TransactionScope())
{
    var portalController = new PortalController();

    var portalId =
        portalController.CreatePortal(
                    "TESTTESTTEST",
                    string.Empty,
                    string.Empty,
                    "TESTTESTTEST_" + new Random().Next(999999),
                    UserController.GeneratePassword(),
                    "TESTTESTTEST_" + new Random().Next(999999) + "@something.com",
                    string.Empty,
                    string.Empty,
                    Globals.ApplicationMapPath + "/Portals/_default/",
                    "Default Website.template",
                    "Portals/TESTTEST",
                    "TESTTESTTEST",
                    string.Empty,
                    string.Empty,
                    false);

    ts.Complete();
}

If I'm using DataProvider.Instance().GetTransaction and performs RollbackTransaction at the end - IT DOES NOT ROLLBACK, which means that the transaction didn't even work.

var t = Data.DataProvider.Instance().GetTransaction();

var portalController = new PortalController();

var portalId =
    portalController.CreatePortal(
                "TESTTESTTEST",
                string.Empty,
                string.Empty,
                "TESTTESTTEST_" + new Random().Next(999999),
                UserController.GeneratePassword(),
                "TESTTESTTEST_" + new Random().Next(999999) + "@something.com",
                string.Empty,
                string.Empty,
                Globals.ApplicationMapPath + "/Portals/_default/",
                "Default Website.template",
                "Portals/TESTTEST",
                "TESTTESTTEST",
                string.Empty,
                string.Empty,
                false);

Data.DataProvider.Instance().RollbackTransaction(t);

So, How to use transactions in DotNetNuke?

+1  A: 

When you create a transaction through the GetTransaction method, the DataProvider just creates a new connection and gives you the transaction. You would then need to manually use that transaction to perform whatever action you're going to take against the database. There isn't a way to pass that transaction so that it gets used by, for example, CreatePortal, or any other built-in DNN function. That functionality appears to be just for any additional database access you might make.

In terms of how to wrap a call from the DNN core in a transaction, I don't think you can. The cleanest solution I know to recommend (which, unfortunately, still isn't very clean) is to manually call the stored procedure, using a transaction, rather than going through the controller class.

What's your use case, maybe I can recommend a solution that solves the problem some other way...

bdukes
My main problem is using DNN entities and my LINQ entities inside a single transaction. The problem shown above is just an obstacle toward the solution of my bigger problem.
Eran Betzalel
Anyway, how come DNN 5.X does not support `TransactionScope`?!
Eran Betzalel