Share via


Mapping Generic Restrictions to Datasource Requirements

The Visual Studio metadata engine drives the enumeration of object types by specifying the type name along with restrictions for a given enumeration. It is up to the data object type, then, to provide information to convert the type name and restrictions into an enumeration call. However, because restrictions are necessarily data-source-specific, you must have a set of generic restrictions for each mapped type, and further, a way to convert these generic restrictions into the actual data-source-specific restrictions in order to enumerate the correct set of objects.

In order for the metadata engine to provide data source objects that map to generic types with generic identifiers and properties, the metadata engine needs a method to let clients specify a set of generic objects to enumerate. At the level of the data source, the method is to use restrictions to limit the set of data objects enumerated by the data provider.

However, these restrictions are necessarily data-source-specific and thus cannot be used directly by a generic client. Therefore, a set of generic restrictions must be associated with each mapped type; furthermore, there must be a way to convert these generic restrictions to the corresponding data-source-specific restrictions that are needed to enumerate a given set of data objects.

Mapping Restrictions

As with mapping of data-source-specific data to generic concepts (see Mapping Object Type Identifiers and Properties to Generic Types), a problem results whenever you map data-source-specific to generic restrictions. Ambiguity can result, for example, when a generic restriction represents multiple data-source-specific restrictions, or vice versa. In other Help topics we refer to this as the b:g problem.

A solution is provided in the XML schema file, which allows a data provider to specify a custom conversion to a data-source-specific restriction, given one or more generic restriction values.

Specifically, when a data provider specifies a mapped element that is associated with a given object type, it is possible to add attributes that describe the necessary restrictions, filter, and sort. Within the restrictions and filter, it is possible to include a data specifier that provides the appropriate value for a generic restriction. Consider the following example:

<MappedType name="Table" underlyingType="Table" />
    <Selection restrictions="{Schema},{Name}"/>
</MappedType>

In this example, the provider indicates that the values of the generic restrictions Schema and Name for the table mapped type should be mapped to the back-end-specific restrictions with the schema first and the name second.

In cases where there is no direct mapping between generic and source-specific restrictions, the provider can add and reference substitution values from within the data specifier, as in the following example:

<MappedType name="Table" underlyingType="Table" />
    <Selection restrictions="{Schema},{Name},{0}">
        <SubstitutionValue mappedRestriction="Type">
            <Conversion>
                <Calculate expr="IIF({0}='SYSTEM',true,false)"                       type="System.Boolean"/>
            </Conversion>
        </SubstitutionValue>
    </Selection>
</Concept>

In this example, the provider has a third restriction, IsSystemObject, which is a Boolean value specifying the kind of objects that should be enumerated. If unspecified, all objects are enumerated; if false, only user objects are enumerated; if true, only system objects are enumerated.

Further, suppose the Table mapped type has a generic restriction, Type, whose value is either "USER" or "SYSTEM." Since there is no direct mapping between these two formats, the provider adds a substitution value that takes the value of the "Type" restriction and uses an expression to convert it to the equivalent Boolean value. Then the data provider uses a data specifier to reference the substitution value. The data specifier completes the reference using an index into the set of substitution values that you specified on the MappedType element. In this case, only one value is specified.

See Also

Concepts

Mapping Object Type Identifiers and Properties to Generic Types

DDEX Data Object Support