共用方式為


ScalarProperty 項目 (MSL)

在對應規格語言 (MSL) 中的 ScalarProperty 項目會對應概念模型實體類型、複雜型別上的屬性,或對應基礎資料庫中之資料表資料行或預存程序參數的關聯。

Bb399167.note(zh-tw,VS.100).gif注意:
修改函式所對應的預存程序必須在儲存模型中宣告。如需詳細資訊,請參閱Function 項目 (SSDL)

ScalarProperty 項目可以是下列項目的子項目:

ScalarProperty 項目做為 MappingFragmentComplexPropertyEndProperty 項目的子項目時,它會將概念模型中的屬性對應至資料庫中的資料行。 ScalarProperty 項目做為 InsertFunctionUpdateFunctionDeleteFunction 項目的子項目時,它會將概念模型中的屬性對應至預存程序參數。

ScalarProperty 項目不能有任何子項目。

適用屬性

套用至 ScalarProperty 項目的屬性會依項目角色而有所不同。

下表描述在 ScalarProperty 項目用來將概念模型屬性對應至資料庫中的資料行時可適用的屬性:

屬性名稱 必要

Name

要對應的概念模型屬性名稱。

ColumnName

要對應的資料表資料行名稱。

下表描述在 ScalarProperty 項目用來將概念模型屬性對應至預存程序參數時可適用的屬性:

屬性名稱 必要

Name

要對應的概念模型屬性名稱。

ParameterName

要對應的參數名稱。

Version

CurrentOriginal 是根據屬性的目前值或原始值是否應該用於並行存取檢查而定。

範例

下列範例顯示用於兩種方式的 ScalarProperty 項目。

  • Person 實體類型的屬性對應至 Person 資料表的資料行。

  • Person 實體類型的屬性對應至 UpdatePerson 預存程序的參數。 預存程序已宣告於儲存模型中。

<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>
      <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>
</EntitySetMapping>

範例

下列範例顯示用來對應資料庫中預存程序之概念模型關聯的插入和刪除函式之 ScalarProperty 項目。 預存程序已宣告於儲存模型中。

<AssociationSetMapping Name="CourseInstructor" 
                       TypeName="SchoolModel.CourseInstructor" 
                       StoreEntitySet="CourseInstructor">
  <EndProperty Name="Person">
    <ScalarProperty Name="PersonID" ColumnName="PersonID" />
  </EndProperty>
  <EndProperty Name="Course">
    <ScalarProperty Name="CourseID" ColumnName="CourseID" />
  </EndProperty>
  <ModificationFunctionMapping>
    <InsertFunction FunctionName="SchoolModel.Store.InsertCourseInstructor" >   
      <EndProperty Name="Course">
        <ScalarProperty Name="CourseID" ParameterName="courseId"/>
      </EndProperty>
      <EndProperty Name="Person">
        <ScalarProperty Name="PersonID" ParameterName="instructorId"/>
      </EndProperty>
    </InsertFunction>
    <DeleteFunction FunctionName="SchoolModel.Store.DeleteCourseInstructor">
      <EndProperty Name="Course">
        <ScalarProperty Name="CourseID" ParameterName="courseId"/>
      </EndProperty>
      <EndProperty Name="Person">
        <ScalarProperty Name="PersonID" ParameterName="instructorId"/>
      </EndProperty>
    </DeleteFunction>
  </ModificationFunctionMapping>
</AssociationSetMapping>

另請參閱

其他資源

CSDL、SSDL 和 MSL 規格
模型及對應 (Entity Framework)