/// <summary> /// Delete a set of values from a Defined Type. /// </summary> /// <param name="definedTypeGuidString">A string representing the Guid identifier of the <see cref="Rock.Model.DefinedType"/> to which a new value will be added.</param> /// <param name="values">A collection of strings containing the Values of the <see cref="Rock.Model.DefinedValue"/> entries to be deleted.</param> public void DeleteValues(string definedTypeGuidString, IEnumerable <string> values) { if (values == null) { return; } var valueList = values.ToList(); if (!valueList.Any()) { return; } var dataContext = ( RockContext )this.Context; // Resolve the Defined Type. var definedType = DefinedTypeCache.Get(new Guid(definedTypeGuidString)); if (definedType == null) { throw new Exception($"Defined Type is invalid. Could not map identifier \"{ definedTypeGuidString }\" to an existing Defined Type."); } // Delete the existing Defined Value if it exists. var definedValueService = new DefinedValueService(dataContext); var definedValues = definedValueService.Queryable().Where(x => x.DefinedTypeId == definedType.Id && valueList.Contains(x.Value)); if (definedValues.Any()) { definedValueService.DeleteRange(definedValues); dataContext.SaveChanges(); } }