DeletedMetadataCollection Class

 

Updated: November 29, 2016

Applies To: Dynamics 365 (online), Dynamics 365 (on-premises), Dynamics CRM 2016, Dynamics CRM Online

The structure used to return deleted metadata.

Namespace:   Microsoft.Xrm.Sdk.Metadata.Query
Assembly:  Microsoft.Xrm.Sdk (in Microsoft.Xrm.Sdk.dll)

System.Object
  Microsoft.Xrm.Sdk.DataCollection<TKey, TValue>
    Microsoft.Xrm.Sdk.Metadata.Query.DeletedMetadataCollection

[CollectionDataContractAttribute(Name = "DeletedMetadataCollection", 
	Namespace = "http://schemas.microsoft.com/xrm/2011/Metadata/Query")]
public sealed class DeletedMetadataCollection : DataCollection<DeletedMetadataFilters, DataCollection<Guid>>

NameDescription
System_CAPS_pubmethodDeletedMetadataCollection()

Initializes a new instance of the DeletedMetadataCollection class.

NameDescription
System_CAPS_pubpropertyCount

Gets the number of elements in the collection.(Inherited from DataCollection<TKey, TValue>.)

System_CAPS_pubpropertyIsReadOnly

Gets a value indicating whether the DataCollection<TKey, TValue> is read-only.(Inherited from DataCollection<TKey, TValue>.)

System_CAPS_pubpropertyItem[TKey]

Gets or sets the value associated with the specified key.(Inherited from DataCollection<TKey, TValue>.)

System_CAPS_pubpropertyKeys

Gets a collection containing the keys in the DataCollection<TKey, TValue>.(Inherited from DataCollection<TKey, TValue>.)

System_CAPS_pubpropertyValues

Gets a collection containing the values in the DataCollection<TKey, TValue>.(Inherited from DataCollection<TKey, TValue>.)

NameDescription
System_CAPS_pubmethodAdd(TKey, TValue)

Adds the specified key and value to the dictionary.(Inherited from DataCollection<TKey, TValue>.)

System_CAPS_pubmethodAdd(KeyValuePair<TKey, TValue>)

Adds the specified key and value to the dictionary.(Inherited from DataCollection<TKey, TValue>.)

System_CAPS_pubmethodAddRange(IEnumerable<KeyValuePair<TKey, TValue>>)

Adds the elements of the specified collection to the end of the DataCollection<TKey, TValue>.(Inherited from DataCollection<TKey, TValue>.)

System_CAPS_pubmethodAddRange(KeyValuePair<TKey, TValue>[])

Adds the elements of the specified collection to the end of the DataCollection<TKey, TValue>.(Inherited from DataCollection<TKey, TValue>.)

System_CAPS_pubmethodClear()

Removes all items from the DataCollection<TKey, TValue>. (Inherited from DataCollection<TKey, TValue>.)

System_CAPS_pubmethodContains(TKey)

Determines whether the DataCollection<TKey, TValue> contains a specific value.(Inherited from DataCollection<TKey, TValue>.)

System_CAPS_pubmethodContains(TKey)

Determines whether the DataCollection<TKey, TValue> contains a specific value.(Inherited from DataCollection<TKey, TValue>.)

System_CAPS_pubmethodContainsKey(TKey)

Determines whether the DataCollection<TKey, TValue> contains a specific key value.(Inherited from DataCollection<TKey, TValue>.)

System_CAPS_pubmethodCopyTo(KeyValuePair<TKey, TValue>[], Int32)
System_CAPS_pubmethodEquals(Object)

(Inherited from Object.)

System_CAPS_pubmethodGetEnumerator()

Returns an enumerator that iterates through a collection.(Inherited from DataCollection<TKey, TValue>.)

System_CAPS_pubmethodGetHashCode()

(Inherited from Object.)

System_CAPS_pubmethodGetType()

(Inherited from Object.)

System_CAPS_pubmethodRemove(TKey)

Removes the first occurrence of a specific object from the DataCollection<TKey, TValue>.(Inherited from DataCollection<TKey, TValue>.)

System_CAPS_pubmethodRemove(TKey)

Removes the first occurrence of a specific object from the DataCollection<TKey, TValue>.(Inherited from DataCollection<TKey, TValue>.)

System_CAPS_pubmethodToString()

(Inherited from Object.)

System_CAPS_pubmethodTryGetValue(TKey, TValue)

Gets the value associated with the specified key.(Inherited from DataCollection<TKey, TValue>.)

NameDescription
System_CAPS_pubinterfaceSystem_CAPS_privmethodIEnumerable.GetEnumerator()

Returns an enumerator that iterates through the collection.(Inherited from DataCollection<TKey, TValue>.)

This is the collection returned as the RetrieveMetadataChangesResponse.DeletedMetadata property when the RetrieveMetadataChangesRequest has values set for the ClientVersionStamp and DeletedMetadataFilters properties.

The following code snippets taken from Sample: Query metadata and detect changes show how the DeletedMetadataCollectioncan be used to detect deleted OptionSetMetadata.



protected String updateOptionLabelList(EntityQueryExpression entityQueryExpression, String clientVersionStamp)
{
 //Retrieve metadata changes and add them to the cache
 RetrieveMetadataChangesResponse updateResponse;
 try
 {
  updateResponse = getMetadataChanges(entityQueryExpression, clientVersionStamp, DeletedMetadataFilters.OptionSet);
  addOptionLabelsToCache(updateResponse.EntityMetadata, true);
  removeOptionLabelsFromCache(updateResponse.DeletedMetadata, true);

 }
 catch (FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault> ex)
 {
  // Check for ErrorCodes.ExpiredVersionStamp (0x80044352)
  // Will occur when the timestamp exceeds the Organization.ExpireSubscriptionsInDays value, which is 90 by default.
  if (ex.Detail.ErrorCode == unchecked((int)0x80044352))
  {
   //reinitialize cache
   _optionLabelList.Clear();

   updateResponse = getMetadataChanges(entityQueryExpression, null, DeletedMetadataFilters.OptionSet);
   //Add them to the cache and display the changes
   addOptionLabelsToCache(updateResponse.EntityMetadata, true);

  }
  else
  {
   throw ex;
  }

 }
 return updateResponse.ServerVersionStamp;
}



protected void removeOptionLabelsFromCache(DeletedMetadataCollection DeletedMetadata, Boolean showChanges)
{
 List<OptionSetOption> optionSetOptionsToRemove = new List<OptionSetOption>();

 if (DeletedMetadata.Keys.Contains(DeletedMetadataFilters.OptionSet))
 {
  DataCollection<Guid> optionsetmetadataids = (DataCollection<Guid>)DeletedMetadata[DeletedMetadataFilters.OptionSet];
  foreach (Guid metadataid in optionsetmetadataids)
  {
   foreach (OptionSetOption oso in _optionLabelList)
   {
    if (metadataid == oso.optionsetId)
    {
     optionSetOptionsToRemove.Add(oso);
    }
   }
  }
 }
 foreach (OptionSetOption option in optionSetOptionsToRemove)
 {
  _optionLabelList.Remove(option);
 }
 if (showChanges)
 {
  if (optionSetOptionsToRemove.Count > 0)
  {
   Console.WriteLine("{0} Option Labels removed", optionSetOptionsToRemove.Count);
   Console.WriteLine("{0} Total Option Labels currently cached", _optionLabelList.Count);
   Console.WriteLine("");
  }
  else
  {
   Console.WriteLine("No Option Labels removed.");
   Console.WriteLine("");
  }

 }
}

Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top

Microsoft Dynamics 365

© 2016 Microsoft. All rights reserved. Copyright

Community Additions

ADD
Show: