我很想知道如何在事务中的 SharePoint 上下文中执行一系列操作。例如,我希望能够执行以下操作:
context.BeginTransaction();
listItemA.Update();
listItemB.Update();
context.CommitTransaction();
我知道这对于 OOTB API 是不可能的,但必须有人想出如何做到这一点。是否可以获得对数据库连接的引用以处理事务?还是有其他想法?
我很想知道如何在事务中的 SharePoint 上下文中执行一系列操作。例如,我希望能够执行以下操作:
context.BeginTransaction();
listItemA.Update();
listItemB.Update();
context.CommitTransaction();
我知道这对于 OOTB API 是不可能的,但必须有人想出如何做到这一点。是否可以获得对数据库连接的引用以处理事务?还是有其他想法?
尽管 SharePoint 在技术上使用 SQL 作为存储支持,但我们不应将其视为基于数据库的应用程序。SP 创建了各种各样的虚假文件系统,这是我们通过 API 与之交互的。因此,从开发人员的角度来看,Sharepoint 几乎没有事务。
不幸的是,这就是它的全部内容了 :) 即使考虑尝试直接参与数据库也会导致旧约的痛苦。撕裂衣服,哭泣和咬牙切齿;)
只需使用 Recycle()。在 GUID[] 中跟踪 GUID。如果一个失败打开 de RecycleBin 并通过 GUID 恢复/删除所有
GUID[] guids = new GUID[];
SPWeb web;
SPListItem item;
SPList list;
try
{
foreach item in list
GUID current = item.Recycle()
guids.add(current);
item.Delete();
}
catch{
if one fails : web.RecycleBin.Restore(guids);
}
if all succeed : web.RecycleBin.Delete(guids):
如果您使用版本控制,您可以尝试签出项目、执行更新和签入的解决方案。如果需要回滚,只需撤消签出。
也许可以工作?
Another option is to use workflow, mentioned here. As stated in How Windows SharePoint Services Processes Workflow Activities:
Windows SharePoint Services runs the workflow until it reaches a point where it cannot proceed because it is waiting for some event to occur: for example, a user must designate a task as completed. Only at this "commit point" does Windows SharePoint Services commit the changes made in the previous Windows SharePoint Services-specific workflow activities. Those changes are batched into a single SQL transaction.
Sharepoint 不提供开箱即用的事务支持。这是为 SharePoint 构建 System.Transactions 资源管理器的一个很好的资源, 尽管我会节省工作量并将任何关键数据直接存储到 RDB 中。
没有 Sharepoint 不提供类似 SQL 服务器的事务功能。
正如 Rutger Hemrika 所发布的那样,这是一种比我迄今为止看到的任何其他方法都要好的方法。