我有一个使用for循环迭代行的方法,在for循环内部调用DNN API,该API将父子行插入数据库。每次执行最多可插入1000行数据。我在本地计算机上对其进行了测试,性能非常慢。我正在考虑使用并行编程,但是由于父子关系而依赖于数据插入,因此不确定如何执行此操作。而且我不确定这是否是使用并行编程的好方法。有什么帮助吗?
示例代码
private void AddTab()
{
for (i = 0; i < 1000; i++) {
TabController tabController = new TabController();
var portalSettings = new
DotNetNuke.Entities.Portals.PortalSettings(info.PortalId);
TabInfo tab = new TabInfo();
tab.PortalID = info.PortalId;
tab.TabName = info.TabName;
tab.Title = info.Title;
tab.Description = info.TabName;
tab.KeyWords = info.TabName;
tab.IsVisible = info.IsVisible;
tab.DisableLink = info.IsDisabled;
tab.ParentId = info.ParentId == null ? Null.NullInteger : info.ParentId.GetValueOrDefault();
tab.IsDeleted = false;
tab.Url = "";
tab.SkinSrc = "[G]Skins/HRT.Portal.DNNThemes.Default/Home.ascx";
tab.ContainerSrc = portalSettings.DefaultPortalContainer;
tab.IsSuperTab = false;
var parentPage = tabController.GetTab(portalSettings.HomeTabId, info.PortalId);
//clone parent page permissions
foreach (TabPermissionInfo permission in parentPage.TabPermissions.ToList())
{
tab.TabPermissions.Add(permission);
}
int tabId = tabController.AddTab(tab, true);
}
}