类型映射是数据提供程序定义的数据对象类型映射到 Visual Studio 元数据引擎定义的通用数据类型的过程。
映射的问题数据源特定于常规概念 (映射问题的“b: g”) 发生,则,例如,是其他任何类型的类型的对象类型, as,当唯一键是一个约束时,或者主键都是唯一键。 因此,一个数据源特定类型可能或泛化 (例如, Constraint) 或更新 (如 PrimaryKey、 UniqueKey或 ForeignKey)。 如果一般概念相同方式不会或单个,遇到 b-g 映射问题。
类型映射在四个类似发生:
1:1 类型映射
1: g 键入映射
b: 1 个类型映射
b: g 键入映射
以下各节解决每个用例中。
1:1 类型映射
数据,则提供程序有一个数据源特定类型映射到该泛型映射的类型,一对一映射是最简单的情况以及生成。 通过指定 underlyingType 属性将一对一映射 (该事件在 MappedType 元素,映射泛型映射的类型 (MappedType XML 元素) 传递给数据源特定类型 (类型 XML 元素)。 这在 XML 的示例所示声明:
下面的 XML 从 DataObjectSupport XML 文件显示数据源特定列声明:
<Type name="Column" preferredOrdering="Database, Schema, Table, Id">
<IdentifierRef name="SubSchemaObjectTypeIdentifier" arguments="Table" />
<Properties>
<PropertyListRef name="ColumnProperties" />
<Property name="Computed" type="System.Boolean" />
</Properties>
<Services>
<ServiceRef name="SubSchemaObjectTypeObjectSelectorService" arguments="Table, Table, Column, ColumnSelectorMappings" />
<ServiceRef name="SubSchemaObjectTypeDSRefBuilderService" arguments="Table, 101, Field, 102" />
</Services>
</Type>
下面的 XML 从 DataObjectSupport XML 文件演示映射到上面列类型通过 underlyingType 属性 TableColumn 泛型映射的类型的声明:
<MappedType name="TableColumn" underlyingType="Column">
<Selection restrictions="{Catalog},{Schema},{Table},{Name}" />
<IdentifierRef name="MappedSubTypeIdentifier" arguments="Table" />
<Properties>
<Property name="Name" isIdentifierPart="true" />
<Property name="Ordinal" underlyingMember="Id" />
<PropertyListRef name="MappedSubTypeDataTypeProperties" />
<Property name="IsNullable" underlyingMember="Nullable" />
<Property name="IsComputed" underlyingMember="Computed" />
</Properties>
</MappedType>
若要扩展该示例,请考虑唯一绑定结构在 SQL Server 上。 对于每个唯一约束始终具有索引,并且,显示的唯一约束所有元数据通过索引提供。 一个人都可以添加,然后,唯一键是一个在 SQL Server 的索引。 在泛型概念,索引,以支持适用的情况下它还可能都是唯一键,映射为 1:1 轻松地处理。
1: g 键入映射
大小写映射对泛型映射的类型的数据源特定类型要稍微复杂一些。 为了说明,请考虑上述示例 (对于映射为 1:1,为)。 在这种情况下,但是,泛型映射的类型是 UniqueKey;这将导致 1: 映射的g ,,单个数据源特定类型 (索引) 超过一个表示更多常规映射的类型 ( UniqueKey 和 Index)。 数据提供程序现在需要将多个映射的类型更改为目标类型,如下所示:
<MappedType name="TableUniqueKey" underlyingType="Index">
<Selection restrictions="{Catalog},{Schema},{Table},{Name}" filter="KeyType > 0" />
<IdentifierRef name="MappedSubTypeIdentifier" arguments="Table" />
<Properties>
<Property name="Name" isIdentifierPart="true" />
<Property name="IsPrimary" underlyingMember="KeyType">
<Conversion>
<Calculate expr="IIF({0} = 1, true, false)" exprType="System.Boolean" />
</Conversion>
</Property>
</Properties>
</MappedType>
<MappedType name="Index" underlyingType="Index">
<Selection restrictions="{Catalog},{Schema},{Table},{Name}" />
</MappedType>
注意到 UniqueKey 概念指定的 filter 属性。 这是最佳方式标识数据源特定类型的实例的子集实际表示该常规概念。
b: 1 个类型映射
将多个数据源特定类型的数据提供程序的情况下为单一泛型映射的类型需要指定一个映射的类型在多个基础类型。 例如,假定,数据提供程序定义数据源特定类型 UniqueKey 和 ForeignKey,是类型约束。 然后,假设有一个泛型映射的类型, Constraint,包含所有约束类型。 结果为 b: 1 映射是,多个数据源特定类型由单一泛型映射的类型表示。
启用此情况比上述情况需要更多的 XML,如下面的示例所示:
<Type name="ForeignKey" preferredOrdering="Database, Schema, Table, Name">
…
</Type>
<Type name="UniqueKey" preferredOrdering="Database, Schema, Table, Name">
…
</Type>
<MappedType name="Constraint" underlyingType="ForeignKey">
…
</MappedType>
<MappedType name="Constraint" underlyingType="UniqueKey">
…
</MappedType>
b: g 键入映射
最后,用例映射到多个一般概念的多个数据源特定类型实际上是组合的 1:g 和 b: 1 映射。 例如,假设一个数据源特定数据提供程序从其他约束分隔主键的概念 (例如,从唯一键和外键)。 在这种情况下可以向数据源特定类型 PrimaryKey 和 Constraint。 现在,假设有一个一般概念 UniqueKey 和 ForeignKey, UniqueKey 概念包含母版和唯一键。 这是映射的 b: g ,多个数据源特定类型由多个泛型映射的类型表示。
若要处理这种情况下,应用此映射通过指定的数据提供多个映射的类型在多个数据源特定类型,如以下 XML 所示:
<Type name="PrimaryKey" preferredOrdering="Database, Schema, Table, Name">
…
</Type>
<Type name="Constraint" preferredOrdering="Database, Schema, Table, Name">
…
</Type>
<MappedType name="UniqueKey" underlyingType="PrimaryKey">
…
</MappedType>
<MappedType name="UniqueKey" underlyingType="Constraint">
<Selection restrictions="{Catalog},{Schema},{Table},{Name}" filter="IsUnique = true" />
</MappedType>
<MappedType name="ForeignKey" underlyingType="Constraint">
<Selection restrictions="{Catalog},{Schema},{Table},{Name}" filter="IsForeign = true" />
</MappedType>