private AggregateConfiguration CreateCloneOfAggregateConfigurationPrivate(AggregateConfiguration toClone, ChooseWhichExtractionIdentifierToUseFromManyHandler resolveMultipleExtractionIdentifiers) { var cataRepo = CatalogueRepository; //two cases here either the import has a custom freaky CHI column (dimension) or it doesn't reference CHI at all if it is freaky we want to preserve it's freakyness ExtractionInformation underlyingExtractionInformation; IColumn extractionIdentifier = GetExtractionIdentifierFrom(toClone, out underlyingExtractionInformation, resolveMultipleExtractionIdentifiers); //clone will not have axis or pivot or dimensions other than extraction identifier var newConfiguration = toClone.ShallowClone(); //make it's name follow the naming convention e.g. cic_105_LINK103_MyAggregate EnsureNamingConvention(newConfiguration); //now clear it's pivot dimension, make it not extratcable and make it's countSQL basic/sane newConfiguration.PivotOnDimensionID = null; newConfiguration.IsExtractable = false; newConfiguration.CountSQL = null;//clear the count sql //clone parameters foreach (AnyTableSqlParameter toCloneParameter in toClone.Parameters) { var newParam = new AnyTableSqlParameter((ICatalogueRepository)newConfiguration.Repository, newConfiguration, toCloneParameter.ParameterSQL); newParam.Value = toCloneParameter.Value; newParam.Comment = toCloneParameter.Comment; newParam.SaveToDatabase(); } //now clone it's AggregateForcedJoins foreach (var t in cataRepo.AggregateForcedJoinManager.GetAllForcedJoinsFor(toClone)) { cataRepo.AggregateForcedJoinManager.CreateLinkBetween(newConfiguration, t); } //now give it 1 dimension which is the only IsExtractionIdentifier column var newDimension = new AggregateDimension(cataRepo, underlyingExtractionInformation, newConfiguration); //the thing we were cloning had a freaky CHI column (probably had a collate or something involved in it or a masterchi) if (extractionIdentifier is AggregateDimension) { //preserve it's freakyness newDimension.Alias = extractionIdentifier.Alias; newDimension.SelectSQL = extractionIdentifier.SelectSQL; newDimension.Order = extractionIdentifier.Order; newDimension.SaveToDatabase(); } //now rewire all it's filters if (toClone.RootFilterContainer_ID != null) //if it has any filters { //get the tree AggregateFilterContainer oldRootContainer = toClone.RootFilterContainer; //clone the tree var newRootContainer = oldRootContainer.DeepCloneEntireTreeRecursivelyIncludingFilters(); newConfiguration.RootFilterContainer_ID = newRootContainer.ID; } newConfiguration.SaveToDatabase(); return(newConfiguration); }