Compartir a través de


Northwind Mapping Schema (EDM)

Mapping specifications connect conceptual types to corresponding storage structures in a target database. Mapping syntax is called mapping specification language (MSL). MSL files have the .msl extension. For more information about mapping, seeMapping Specification (MSL).

The <EntityContainerMapping> tag in an MSL file maps the EntityContainer of the conceptual schema definition language (CSDL) schema to the StorageEntityContainer in a database object. Similarly, <EntitySetMapping> and <EntityTypeMapping> tags map entity sets and types from the MSL schema to corresponding structures in the target database.

Note

In the XML hierarchy, the EntityContainer element is separate from the Schema element even though the EntityContainer is defined in the schema. The name of the EntityContainer does not include the schema namespace name in the mapping file. The use of an entity container name qualified by the schema namespace name causes a mapping exception.

The complete contents of the Northwind MSL file are shown in the following example.

<?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>

For more information about schemas and mapping, see Schemas and Mapping Specification (Entity Framework).

For more information about defining entities and associations, see Implementing Entities (EDM)

Implementing Associations (EDM).

See Also

Concepts

Entity Data Model Types
Entity Data Model Relationships

Other Resources

Schemas and Mapping Specification (Entity Framework)