Partilhar via


Condition Element (MSL)

The Condition element in mapping specification language (MSL) places conditions on mappings between the conceptual model and the underlying database. The mapping that is defined within an XML node is valid if all conditions, as specified in child Condition elements, are met. Otherwise, the mapping is not valid. For example, if a MappingFragment element contains one or more Condition child elements, the mapping defined within the MappingFragment node will only be valid if all the conditions of the child Condition elements are met.

Each condition can apply to either a Name (the name of a conceptual model entity property, specified by the Name attribute), or a ColumnName (the name of a column in the database, specified by the ColumnName attribute). When the Name attribute is set, the condition is checked against an entity property value. When the ColumnName attribute is set, the condition is checked against a column value. Only one of the Name or ColumnName attribute can be specified in a Condition element.

Note

When the Condition element is used within a FunctionImportMapping element, only the Name attribute is not applicable.

The Condition element can be a child of the following elements:

The Condition element can have no child elements.

Applicable Attributes

The following table describes the attributes that are applicable to the Condition element:

Attribute Name Is Required Value

ColumnName

No

The name of the table column whose value is used to evaluate the condition.

IsNull

No

True or False. If the value is True and the column value is null, or if the value is False and the column value is not null, the condition is true. Otherwise, the condition is false.

The IsNull and Value attributes cannot be used at the same time.

Value

No

The value with which the column value is compared. If the values are the same, the condition is true. Otherwise, the condition is false.

The IsNull and Value attributes cannot be used at the same time.

Name

No

The name of the conceptual model entity property whose value is used to evaluate the condition.

This attribute is not applicable if the Condition element is used within a FunctionImportMapping element.

Example

The following example shows Condition elements as children of MappingFragment elements. When HireDate is not null and EnrollmentDate is null, data is mapped between the SchoolModel.Instructor type and the PersonID and HireDate columns of the Person table. When EnrollmentDate is not null and HireDate is null, data is mapped between the SchoolModel.Student type and the PersonID and Enrollment columns of the Person table.

<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

Other Resources

CSDL, SSDL, and MSL Specifications
Modeling and Mapping