private static void UpdateRegionVmOsMappings(IEnumerable <AzureCatalogue> azureCatalogueResult) { var cmpWapDb = new CmpWapDb(); var cmpWapRegions = cmpWapDb.FetchAzureRegionList(onlyActiveOnes: false).ToList(); var cmpWapVmOses = cmpWapDb.FetchOsInfoList(onlyActiveOnes: false).ToList(); var newMappings = new List <AzureRegionVmOsMapping>(); try { foreach (var regionInCatalogue in azureCatalogueResult) { foreach (var vmOs in regionInCatalogue.VmOses) { //Since we format the VmOs name when inserting it into the DB table, to look it up, we will need to do the same format operation as before var vmOsName = (vmOs.Publisher + ", " + vmOs.Offer + ", " + vmOs.SKU).Length >= 100 ? (vmOs.Publisher + ", " + vmOs.Offer + ", " + vmOs.SKU).Substring(0, 100) : (vmOs.Publisher + ", " + vmOs.Offer + ", " + vmOs.SKU); //Adjusting for DB limitations in length, so that the logic comparison does not fail //We need to get the IDs to make the mapping object. Query the VmOs and Region tables to get them. var vmOsToMap = cmpWapVmOses.FirstOrDefault(x => string.Equals(vmOsName, x.Name, StringComparison.InvariantCultureIgnoreCase)); var regionToMap = cmpWapRegions.FirstOrDefault(y => string.Equals(regionInCatalogue.RegionName.Replace(" ", string.Empty), y.Name.Replace(" ", string.Empty), StringComparison.InvariantCultureIgnoreCase)); if (vmOsToMap == null || regionToMap == null) { continue; //something's wrong here if we reach this. } var newMapping = new AzureRegionVmOsMapping { AzureRegionId = regionToMap.AzureRegionId, VmOsId = vmOsToMap.VmOsId, IsActive = true }; newMappings.Add(newMapping); } } if (newMappings.Any()) { cmpWapDb.SetRegionVmOsMappingsByBatch(newMappings); } } catch (Exception ex) { throw new Exception("Exception caught in UpdateRegionVmOsMappings: " + ex.ToString()); } }