Please find below code where I am trying to acheive parallel deleting of all products in sitefinity. Looks like there is a scoping issue.
using (CatalogManager catMgr = CatalogManager.GetManager())
List<Product> products = catMgr.GetProducts().ToList();
Parallel.ForEach(products, product =>
This code gives the error <b>Object references between two different object scopes are not allowed. The object 'Telerik.Sitefinity.DynamicTypes.Model.sf_ec_prdct_generalproduct' is already managed by 'ObjectScopeImpl 0x38 OpenAccessRuntime.EnlistableObjectScope' and was tried to be managed again by 'ObjectScopeImpl 0xfd OpenAccessRuntime.EnlistableObjectScope'.</b>
Please let me know in case I am missing something.
Thank you for your reply. Please let me know in case there is any alternative to parallely delete multiple records. I cannot rely on one by one delete as I have approximately 200,000 records and it is taking a very lot of time.
Anything similar to insert multiple users/products/orders. Please note all are new users/products/orders.
This task is for migrating from existing ecomm database to sitefinity database.
Based on the suggestion I did write the code in batches but it still seem to be slow. I tried batches of 10. Please find my codesnippet below. catalogmanager.SaveChanges() for 10 products takes a long time. Please check and let me know in case I missed anything.
private void DeleteProducts(DynamicModuleManager dynamicModuleManager, DynamicContent content, IEnumerable<ProductImportCSV> products)
DynamicContent dynamicItemMaster = dynamicModuleManager.Lifecycle.Edit(content) as DynamicContent;
if (dynamicItemMaster == null)
throw new ApplicationException("DeleteProducts Product Dynamic Item Master was null!");
DynamicContent dynamicItemTemp = dynamicModuleManager.Lifecycle.CheckOut(dynamicItemMaster) as DynamicContent;
if (dynamicItemTemp == null)
throw new ApplicationException("DeleteProducts Product Dynamic Item Temp was null!");
Guid vendorid = content.GetValue<Guid>(BatchUploadConstants.VendorId);
using (CatalogManager catalogManager = CatalogManager.GetManager())
catalogManager.Provider.SuppressSecurityChecks = true;
IEnumerable<ProductImportCSV> productImportCsvs = products as IList<ProductImportCSV> ?? products.ToList();
// ignore empty records. most likely issue with csv
productImportCsvs = productImportCsvs.Where(p => !string.IsNullOrEmpty(p.SKU));
IQueryable<Product> masterProducts = catalogManager.GetProducts().Where(p => p.Status == ContentLifecycleStatus.Master );
var deleteMasterProducts = Enumerable.Where(masterProducts, p => p.GetValue<TrackedList<Guid>>(DynamicProductConstants.Category).Contains(vendorid));
// Run in batches
int skip = 0;
int take = _batchSize == 0 ? 10 : _batchSize;
int currentCount = 0;
int totalCount = deleteMasterProducts.Count();
while (currentCount < totalCount)
string skusNotDeleted = string.Empty;
var chunkedProducts = deleteMasterProducts.Skip(skip).Take(take);
skip = skip + take;
currentCount = skip;
foreach (Product product in chunkedProducts)
skusNotDeleted += product.Sku + " ,";
_errorLog.Append(" SKUs not deleted are : " + skusNotDeleted + ". ");
catch (Exception ex)
_errorLog.Append("Error occurred while deleting and exception message is : " + ex.Message + " " + Environment.NewLine);
CatalogManager catalogManager = CatalogManager.GetManager();
var products = catalogManager.GetProducts();
To delete the records i have used below code.
I have created the records using the dynamic module and wanted to delete all old records so i have write the code like below. may be this code helpful to other
public static void DeleteAllUnclaimedDividendRecords()
DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager();
Type unclaimedDividendType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.UnclaimedDividend.UnclaimedDividend");
var myCollection = dynamicModuleManager.GetDataItems(unclaimedDividendType);
foreach (var item in myCollection)