如何在DotNetNuke中使用交易? [英] How to use transactions in DotNetNuke?
问题描述
我正在尝试做最简单的事情,并将事务应用于 CreatePortal
方法。
I'm trying to do the most simple thing and apply a transaction to the CreatePortal
method.
如果我使用 TransactionScope
-由于某些未知原因,它会升级为DTC-BAD。
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();
}
如果我使用的是 DataProvider.Instance() .GetTransaction
并最终执行 RollbackTransaction
-它不会回滚,这意味着该交易甚至无法正常工作。
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);
那么,如何在DotNetNuke中使用事务?
So, How to use transactions in DotNetNuke?
推荐答案
通过 GetTransaction
方法创建事务时, DataProvider
只会创建一个新的连接并为您提供交易。然后,您需要手动使用该事务来对数据库执行任何操作。没有一种方法可以传递该事务,以使它被 CreatePortal
或任何其他内置的DNN函数使用。该功能似乎仅用于您可能进行的任何其他数据库访问。
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.
关于如何在事务中包装来自DNN核心的调用,我不是认为可以。我知道推荐的最干净的解决方案(不幸的是,它仍然不是很干净)是使用事务手动调用存储过程,而不是通过控制器类。
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...
这篇关于如何在DotNetNuke中使用交易?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!