Udostępnij za pośrednictwem


PropertyRef Element (CSDL)

The PropertyRef element in conceptual schema definition language (CSDL) references a property of an entity type to indicate that the property will perform one of the following roles:

  • Part of the entity's key (a property or a set of properties of an entity type that determine identity). One or more PropertyRef elements can be used to define an entity key. For more information, see Key element.

  • The dependent or principal end of a referential constraint. For more information, see ReferentialConstraint element.

The PropertyRef element can only have annotation elements (zero or more) as child elements.

Note

Annotation elements are only allowed in conceptual models for applications that target the .NET Framework version 4 or later. The XML namespace for such models is https://schemas.microsoft.com/ado/2008/09/edm.

Applicable Attributes

The table below describes the attributes that can be applied to the PropertyRef element.

Attribute Name Is Required Value

Name

Yes

The name of the referenced property.

Note

Any number of annotation attributes (custom XML attributes) may be applied to the PropertyRef element. However, custom attributes may not belong to any XML namespace that is reserved for CSDL. The fully-qualified names for any two custom attributes cannot be the same.

Example

The example below defines an entity type (Book). The entity key is defined by referencing the ISBN property of the entity type.

<EntityType Name="Book">
  <Key>
    <PropertyRef Name="ISBN" />
  </Key>
  <Property Type="String" Name="ISBN" Nullable="false" />
  <Property Type="String" Name="Title" Nullable="false" />
  <Property Type="Decimal" Name="Revision" Nullable="false" Precision="29" Scale="29" />
  <NavigationProperty Name="Publisher" Relationship="BooksModel.PublishedBy"
                      FromRole="Book" ToRole="Publisher" />
  <NavigationProperty Name="Authors" Relationship="BooksModel.WrittenBy"
                      FromRole="Book" ToRole="Author" />
</EntityType>

In the next example, two PropertyRef elements are used to indicate that two properties (Id and PublisherId) are the principal and dependent ends of a referential constraint.

<Association Name="PublishedBy">
  <End Type="BooksModel.Book" Role="Book" Multiplicity="*" >
  </End>
  <End Type="BooksModel.Publisher" Role="Publisher" Multiplicity="1" />
  <ReferentialConstraint>
    <Principal Role="Publisher">
      <PropertyRef Name="Id" />
    </Principal>
    <Dependent Role="Book">
      <PropertyRef Name="PublisherId" />
    </Dependent>
  </ReferentialConstraint>
</Association>

See Also

Concepts

Entity Framework Overview
CSDL Specification
Schema Element (CSDL)

Other Resources

CSDL, SSDL, and MSL Specifications
ADO.NET Entity Data Model Tools
entity key (Entity Data Model)