共用方式為


Mapping Specification (MSL)

In the Entity Data Model (EDM), the mapping specification uses mapping specification language (MSL) to connect the types declared in conceptual schema definition language (CSDL) to database metadata that persists data for applications that use the object model being defined.

The Namespace Name and EntityContainer Name declared in the CSDL schema identify entities and associations that are contained by the conceptual schema. MSL syntax maps them to store metadata in the store schema definition language (SSDL) file.

The following MSL segment shows the syntax used to map the entity container HumanResources, as defined in the CSDL schema, to the corresponding entity container HumanResources, as defined in the SSDL schema, describing the target database.

The names of entity containers assigned to CdmEntityContainer and StorageEntityContainer are not qualified by the Namespace name of the schemas in which they are declared. Even though the entity containers are declared within schemas, they are separate and independent from the schemas.

<?xml version="1.0" encoding="utf-8"?>
<Mapping Space="C-S" 
    xmlns="urn:schemas-microsoft-com:windows:storage:mapping:CS">

  <EntityContainerMapping CdmEntityContainer="HumanResources"
StorageEntityContainer="HumanResources">

Entity sets that are contained by entity containers are mapped using syntax similar to that used for entity containers. The following mapping connects the entity set that is named AdventureWorksHRModel.Department, from the conceptual schema to a table named Department in the storage metadata. The EntitySetMapping element includes a Name attribute identifying the Department entity set in both the conceptual schema and in the storage metadata.

The EntityTypeMapping element includes a TypeName attribute for Department entity in the CSDL schema with a corresponding MappingFragment and TableName attribute for the Department table in the database.

Finally, ScalarProperty elements correspond to the Name of a property of an entity in the CSDL schema to a ColumnName in the Department table in the SSDL schema.

    <EntitySetMapping Name="Department">
      <EntityTypeMapping
                   TypeName="AdventureWorksHRModel.Department">
        <MappingFragment TableName="Department">
          <ScalarProperty Name="DepartmentID"
                               ColumnName="DepartmentID" />
          <ScalarProperty Name="Name" ColumnName="Name" />
          <ScalarProperty Name="GroupName"
                                    ColumnName="GroupName" />
          <ScalarProperty Name="ModifiedDate"
                                 ColumnName="ModifiedDate" />
        </MappingFragment>
      </EntityTypeMapping>
    </EntitySetMapping>

Xmlns

MSL schemas are in the XML namespace: urn:schemas-microsoft-com:windows:storage:mapping:CS.

EntitySetMapping Element (MSL)

EntityContainerMapping Element (MSL)

AssociationSetMapping Element (MSL)

See Also

Concepts

Conceptual Schema (CSDL)
Storage Metadata Schema (SSDL)
AdventureWorks Complete Model (EDM)
Data Modeling in the Entity Framework