Northwind 映射架构 (EDM)
映射规范将概念类型与目标数据库中相应的存储结构联系起来。映射语法称为映射规范语言 (MSL)。MSL 文件具有 .msl 扩展名。有关映射的更多信息,请参见映射规范 (MSL)。
MSL 文件中的 <EntityContainerMapping> 标记将概念性架构定义语言 (CSDL) 架构的 EntityContainer 映射到数据库对象中的 StorageEntityContainer。与此类似,<EntitySetMapping> 和 <EntityTypeMapping> 标记将 MSL 架构中的实体集和类型映射到目标数据库中相应的结构。
注意 |
---|
在 XML 层次结构中,EntityContainer 元素与 Schema 元素分开,即使 EntityContainer 是在架构中定义的,也是如此。EntityContainer 的名称不包括映射文件中的架构命名空间名称。使用由架构命名空间名称限定的实体容器名称会导致映射异常。 |
下面的示例显示了 Northwind MSL 文件的完整内容。
<?xml version="1.0" encoding="utf-8"?>
<Mapping xmlns="urn:schemas-microsoft-com:windows:storage:mapping:CS"
xmlns:edm="urn:schemas-microsoft-com:windows:storage:mapping:CS"
Space="C-S">
<EntityContainerMapping CdmEntityContainer="Northwind" StorageEntityContainer="dbo">
<EntitySetMapping Name="Categories">
<EntityTypeMapping TypeName="NorthwindLib.Category">
<MappingFragment StoreEntitySet="Categories">
<ScalarProperty Name="CategoryID" ColumnName="CategoryID" />
<ScalarProperty Name="CategoryName" ColumnName="CategoryName" />
<ScalarProperty Name="Description" ColumnName="Description" />
</MappingFragment>
</EntityTypeMapping>
</EntitySetMapping>
<EntitySetMapping Name="Products">
<EntityTypeMapping TypeName="NorthwindLib.Product">
<MappingFragment StoreEntitySet="Products">
<ScalarProperty Name="ProductID" ColumnName="ProductID" />
<ScalarProperty Name="ProductName" ColumnName="ProductName" />
<!--<ScalarProperty edm:Name="CategoryID"
edm:ColumnName="CategoryID" />-->
<ScalarProperty Name="UnitPrice" ColumnName="UnitPrice" />
<Condition ColumnName="Discontinued" Value="false" />
</MappingFragment>
</EntityTypeMapping>
<EntityTypeMapping TypeName="NorthwindLib.DiscontinuedProduct">
<MappingFragment StoreEntitySet="Products">
<ScalarProperty Name="ProductID" ColumnName="ProductID" />
<ScalarProperty Name="ProductName" ColumnName="ProductName" />
<!--<ScalarProperty edm:Name="CategoryID"
edm:ColumnName="CategoryID" />-->
<ScalarProperty Name="UnitPrice" ColumnName="UnitPrice" />
<ScalarProperty Name="UnitsInStock" ColumnName="UnitsInStock" />
<Condition ColumnName="Discontinued" Value="true" />
</MappingFragment>
</EntityTypeMapping>
</EntitySetMapping>
<EntitySetMapping Name="Customers">
<EntityTypeMapping TypeName="NorthwindLib.Customer">
<MappingFragment StoreEntitySet="Customers">
<ScalarProperty Name="CustomerID" ColumnName="CustomerID" />
<ScalarProperty Name="CompanyName" ColumnName="CompanyName" />
<ScalarProperty Name="ContactName" ColumnName="ContactName" />
<ScalarProperty Name="City" ColumnName="City" />
<ScalarProperty Name="Country" ColumnName="Country" />
</MappingFragment>
</EntityTypeMapping>
</EntitySetMapping>
<EntitySetMapping Name="SalesOrders">
<EntityTypeMapping TypeName="NorthwindLib.SalesOrder">
<MappingFragment StoreEntitySet="Orders">
<ScalarProperty Name="OrderID" ColumnName="OrderID" />
<!--<ScalarProperty edm:Name="CustomerID"
edm:ColumnName="CustomerID" /> -->
<ScalarProperty Name="OrderDate" ColumnName="OrderDate" />
<ScalarProperty Name="ShipCity" ColumnName="ShipCity" />
<ScalarProperty Name="ShipCountry" ColumnName="ShipCountry" />
</MappingFragment>
</EntityTypeMapping>
</EntitySetMapping>
<AssociationSetMapping Name="CustomerOrders" TypeName="NorthwindLib.Customer_Order"
StoreEntitySet="Orders">
<EndProperty Name="Customer">
<ScalarProperty Name="CustomerID" ColumnName="CustomerID" />
</EndProperty>
<EndProperty Name="SalesOrder">
<ScalarProperty Name="OrderID" ColumnName="OrderID" />
</EndProperty>
</AssociationSetMapping>
<AssociationSetMapping Name="CategoryProducts" TypeName="NorthwindLib.Category_Product"
StoreEntitySet="Products">
<EndProperty Name="Category">
<ScalarProperty Name="CategoryID" ColumnName="CategoryID" />
</EndProperty>
<EndProperty Name="Product">
<ScalarProperty Name="ProductID" ColumnName="ProductID" />
</EndProperty>
</AssociationSetMapping>
</EntityContainerMapping>
</Mapping>
有关架构和映射的更多信息,请参见架构和映射规范(实体框架)。
有关定义实体和关联的更多信息,请参见实现实体 (EDM)。