Selecting Items in a Collection

Meta Data Services Programming

Meta Data Services Programming

Selecting Items in a Collection

You can select the items of a collection by index, by sequence, by enumerator, or by name. If you get a collection for an origin object, or plan to move from an origin object to a destination object, all of these selection options are available. If you get a collection for a destination object, or plan to move from a destination object to an origin object, you have fewer selection options. The availability of a selection option is described in each approach.

You can select collection items in the following ways:

  • By index. Choose the nth item in the collection, where n is a number between one and the size of the collection.

    COM: Use the get_Item method of the IRelationshipCol interface or the ITargetObjectCol interface.

    Automation: Use the syntax collection(index), as for any Automation collection.

  • By sequence. Use the same programming statements to select by sequence as you use to select by index. The distinction between the two depends only on how the repository orders the items in the collection. In most cases, the repository uses an arbitrary order. But if the collection is a sequenced collection, the repository orders the collection items according to the defined sequence.

    This approach is valid when the origin object and the source object are the same. You cannot select by sequence from a collection belonging to a destination object, because the repository does not sequence collections belonging to destination objects.

  • With an enumerator. At the COM level you can get an enumerator object for a collection, and then use the standard enumerator functions (Next, Skip, Reset, and Clone). Use the _NewEnum method of the IRelationshipCol interface or the ITargetObjectCol interface to obtain an interface pointer to an enumerator object.

    For more information, see Using Enumerators to Work with Items in a Collection.

  • By name. If the collection is a collection of names, you can select the item whose name matches the name you supply.

    COM: Use the get_Item method of the IRelationshipCol interface or the ITargetObjectCol interface.

    Automation: Use the syntax myCollection("name").

    Note  You cannot select by name from a collection belonging to a destination object, because a Microsoft® SQL Server™ 2000 Meta Data Services repository does not support the naming of origin objects.

    If a name within the collection of names is not unique, the repository will return the first item that it finds with the specified name.

See Also

Navigating a Repository