Compartilhar via


EntityTypeMapping Element (MSL)

The EntityTypeMapping element in mapping specification language (MSL) defines the mapping between an entity type in the conceptual model and tables or views in the underlying database. For information about conceptual model entity types and underlying database tables or views, see EntityType Element (CSDL) and EntitySet Element (SSDL). The conceptual model entity type that is being mapped is specified by the TypeName attribute of the EntityTypeMapping element. The table or view that is being mapped is specified by the StoreEntitySet attribute of the child MappingFragment element.

The ModificationFunctionMapping child element can be used to map the insert, update, or delete functions of entity types to stored procedures in the database.

The EntityTypeMapping element can have the following child elements:

Note

MappingFragment and ModificationFunctionMapping elements cannot be child elements of the EntityTypeMapping element at the same time.

Note

The ScalarProperty and Condition elements can only be child elements of the EntityTypeMapping element when it is used within a FunctionImportMapping element.

Applicable Attributes

The following table describes the attributes that can be applied to the EntityTypeMapping element.

Attribute Name Is Required Value

TypeName

Yes

The namespace-qualified name of the conceptual model entity type that is being mapped.

If the type is abstract or a derived type, the value must be IsOfType(Namespace-qualified_type_name).

Example

The following example shows an EntitySetMapping element with two child EntityTypeMapping elements. In the first EntityTypeMapping element, the SchoolModel.Person entity type is mapped to the Person table. In the second EntityTypeMapping element, the update functionality of the SchoolModel.Person type is mapped to a stored procedure, UpdatePerson, in the database.

<EntitySetMapping Name="People">
  <EntityTypeMapping TypeName="SchoolModel.Person">
    <MappingFragment StoreEntitySet="Person">
      <ScalarProperty Name="PersonID" ColumnName="PersonID" />
      <ScalarProperty Name="LastName" ColumnName="LastName" />
      <ScalarProperty Name="FirstName" ColumnName="FirstName" />
      <ScalarProperty Name="HireDate" ColumnName="HireDate" />
      <ScalarProperty Name="EnrollmentDate" ColumnName="EnrollmentDate" />
    </MappingFragment>
  </EntityTypeMapping>
  <EntityTypeMapping TypeName="SchoolModel.Person">
    <ModificationFunctionMapping>
      <UpdateFunction FunctionName="SchoolModel.Store.UpdatePerson">
        <ScalarProperty Name="EnrollmentDate" ParameterName="EnrollmentDate" 
                        Version="Current" />
        <ScalarProperty Name="HireDate" ParameterName="HireDate" 
                        Version="Current" />
        <ScalarProperty Name="FirstName" ParameterName="FirstName" 
                        Version="Current" />
        <ScalarProperty Name="LastName" ParameterName="LastName" 
                        Version="Current" />
        <ScalarProperty Name="PersonID" ParameterName="PersonID" 
                        Version="Current" />
      </UpdateFunction>
    </ModificationFunctionMapping>
  </EntityTypeMapping>
</EntitySetMapping>

Example

The next example shows the mapping of a type hierarchy in which the root type is abstract. Note the use of the IsOfType syntax for the TypeName attributes.

<EntitySetMapping Name="People">
  <EntityTypeMapping TypeName="IsTypeOf(SchoolModel.Person)">
    <MappingFragment StoreEntitySet="Person">
      <ScalarProperty Name="PersonID" ColumnName="PersonID" />
      <ScalarProperty Name="FirstName" ColumnName="FirstName" />
      <ScalarProperty Name="LastName" ColumnName="LastName" />
    </MappingFragment>
  </EntityTypeMapping>
  <EntityTypeMapping TypeName="IsTypeOf(SchoolModel.Instructor)">
    <MappingFragment StoreEntitySet="Person">
      <ScalarProperty Name="PersonID" ColumnName="PersonID" />
      <ScalarProperty Name="HireDate" ColumnName="HireDate" />
      <Condition ColumnName="HireDate" IsNull="false" />
      <Condition ColumnName="EnrollmentDate" IsNull="true" />
    </MappingFragment>
  </EntityTypeMapping>
  <EntityTypeMapping TypeName="IsTypeOf(SchoolModel.Student)">
    <MappingFragment StoreEntitySet="Person">
      <ScalarProperty Name="PersonID" ColumnName="PersonID" />
      <ScalarProperty Name="EnrollmentDate" 
                      ColumnName="EnrollmentDate" />
      <Condition ColumnName="EnrollmentDate" IsNull="false" />
      <Condition ColumnName="HireDate" IsNull="true" />
    </MappingFragment>
  </EntityTypeMapping>
</EntitySetMapping>

See Also

Concepts

CSDL Specification
SSDL Specification

Other Resources

Modeling and Mapping