Partilhar via


ResultBinding Element (MSL)

The ResultBinding element in mapping specification language (MSL) maps column values that are returned by stored procedures to entity properties in the conceptual model when entity type modification functions are mapped to stored procedures in the underlying database. For example, when the value of an identity column is returned by an insert stored procedure, the ResultBinding element maps the returned value to an entity type property in the conceptual model.

The ResultBinding element can be child of the InsertFunction element or the UpdateFunction element.

The ResultBinding element cannot have any child elements.

Applicable Attributes

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

Attribute Name Is Required Value

Name

Yes

The name of the entity property in the conceptual model that is being mapped.

ColumnName

Yes

The name of the column being mapped.

Example

The following example is based on the School model and shows an InsertFunction element used to map the insert function of the Person entity type to the InsertPerson stored procedure. (The InsertPerson stored procedure is shown below and is declared in the storage model.) A ResultBinding element is used to map a column value that is returned by the stored procedure (NewPersonID) to an entity type property (PersonID).

<EntityTypeMapping TypeName="SchoolModel.Person">
  <ModificationFunctionMapping>
    <InsertFunction FunctionName="SchoolModel.Store.InsertPerson">
      <ScalarProperty Name="EnrollmentDate"
                      ParameterName="EnrollmentDate" />
      <ScalarProperty Name="HireDate" ParameterName="HireDate" />
      <ScalarProperty Name="FirstName" ParameterName="FirstName" />
      <ScalarProperty Name="LastName" ParameterName="LastName" />
      <ResultBinding Name="PersonID" ColumnName="NewPersonID" />
    </InsertFunction>
    <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>
    <DeleteFunction FunctionName="SchoolModel.Store.DeletePerson">
      <ScalarProperty Name="PersonID" ParameterName="PersonID" />
    </DeleteFunction>
  </ModificationFunctionMapping>
</EntityTypeMapping>

The following Transact-SQL describes the InsertPerson stored procedure:

CREATE PROCEDURE [dbo].[InsertPerson]
        @LastName nvarchar(50),
        @FirstName nvarchar(50),
        @HireDate datetime,
        @EnrollmentDate datetime
        AS
        INSERT INTO dbo.Person (LastName, 
                    FirstName, 
                    HireDate, 
                    EnrollmentDate)
        VALUES (@LastName, 
            @FirstName, 
            @HireDate, 
            @EnrollmentDate);
        SELECT SCOPE_IDENTITY() as NewPersonID;

See Also

Other Resources

CSDL, SSDL, and MSL Specifications
Modeling and Mapping