ReplicaMetadata::CreateItemMetadata Method
When overridden in a derived class, creates a new item metadata object that can be used to add a new item metadata entry to the metadata store.
Assembly: Microsoft.Synchronization.MetadataStorage (in Microsoft.Synchronization.MetadataStorage.dll)
public: virtual ItemMetadata^ CreateItemMetadata( SyncId^ globalId, SyncVersion^ creationVersion ) abstract
Parameters
- globalId
- Type: Microsoft.Synchronization::SyncId
The global ID of the item to create. The global ID must be unique.
- creationVersion
- Type: Microsoft.Synchronization::SyncVersion
The creation version to associate with this item.
Return Value
Type: Microsoft.Synchronization.MetadataStorage::ItemMetadataThe newly created item metadata object.
| Exception | Condition |
|---|---|
| ObjectDisposedException | The object has been disposed or was not initialized correctly. |
| ArgumentNullException | globalId or creationVersion is a nullptr. |
| OutOfMemoryException | There is not enough memory to create the item metadata. |
| SyncIdFormatMismatchException | The format of globalId does not match the format that was specified when the replica metadata was initialized. |
This item metadata is not saved to the metadata store until SaveItemMetadata is called.
The following example creates metadata for an item, sets the change unit version for each change unit in the item, and sets the custom field values for the index fields of the item.
private ItemMetadata CreateContactMetadata(Contact contact, SyncId itemId, SyncVersion creationVersion, SyncVersion changeVersion) { // Create the item by using the metadata storage service. ItemMetadata itemMeta = _ContactReplicaMetadata.CreateItemMetadata(itemId, creationVersion); // Set the version information for each change unit. itemMeta.SetChangeUnitVersion(new SyncId((byte)Contact.ChangeUnitFields.NameCU), changeVersion); itemMeta.SetChangeUnitVersion(new SyncId((byte)Contact.ChangeUnitFields.PhoneCU), changeVersion); itemMeta.SetChangeUnitVersion(new SyncId((byte)Contact.ChangeUnitFields.AddressCU), changeVersion); itemMeta.SetChangeUnitVersion(new SyncId((byte)Contact.ChangeUnitFields.BirthdateCU), changeVersion); // A unique index is defined for the combination of first name, last name, and phone number in order // to map between the item ID and the contact. // Set the field values for the index fields. itemMeta.SetCustomField(FirstNameField, contact.FirstName); itemMeta.SetCustomField(LastNameField, contact.LastName); itemMeta.SetCustomField(PhoneNumberField, contact.PhoneNumber); return itemMeta; }
Show: