Delen via


Property Element (CSDL)

The Property element in conceptual schema definition language (CSDL) can be a child of the EntityType element, the ComplexType element, or the RowType element.

EntityType and ComplexType Element Applications

Property elements (as children of EntityType or ComplexType elements) define the shape and characteristics of data that an entity type instance or complex type instance will contain. Properties in a conceptual model are analogous to properties that are defined on a class. In the same way that properties on a class define the shape of the class and carry information about objects, properties in a conceptual model define the shape of an entity type and carry information about entity type instances.

The Property element can have the following child elements (in the order listed):

The following facets can be applied to a Property element: Nullable, DefaultValue, MaxLength, FixedLength, Precision, Scale, Unicode, Collation, ConcurrencyMode. Facets are XML attributes that provide information about how property values are stored in the data store. For more information, see Facets (CSDL).

Note

Facets can only be applied to properties of type EDMSimpleType. For more information, see Conceptual Model Types (CSDL).

Applicable Attributes

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

Attribute Name Is Required Value

Name

Yes

The name of the property.

Type

Yes

The type of the property value. The property value type must be an EDMSimpleType or a complex type (indicated by a fully-qualified name) that is within scope of the model. For more information, see Conceptual Model Types (CSDL).

Nullable

No

True (the default value) or False depending on whether the property can have a null value.

Bb399546.note(en-us,VS.100).gifNote:
In the version of CSDL indicated by the https://schemas.microsoft.com/ado/2006/04/edm namespace, a complex type property must have Nullable="False".

DefaultValue

No

The default value of the property.

MaxLength

No

The maximum length of the property value.

FixedLength

No

True or False depending on whether the property value will be stored as a fixed length string.

Precision

No

The precision of the property value.

Scale

No

The scale of the property value.

Unicode

No

True or False depending on whether the property value will be stored as a Unicode string.

Collation

No

A string that specifies the collating sequence to be used in the data source.

ConcurrencyMode

No

None (the default value) or Fixed. If the value is set to Fixed, the property value will be used in optimistic concurrency checks.

Note

Any number of annotation attributes (custom XML attributes) may be applied to the Property 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 following example shows an EntityType element with three Property elements:

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

The following example shows a ComplexType element with five Property elements:

<ComplexType Name="Address" >
  <Property Type="String" Name="StreetAddress" Nullable="false" />
  <Property Type="String" Name="City" Nullable="false" />
  <Property Type="String" Name="StateOrProvince" Nullable="false" />
  <Property Type="String" Name="Country" Nullable="false" />
  <Property Type="String" Name="PostalCode" Nullable="false" />
</ComplexType>

RowType Element Application

Property elements (as the children of a RowType element) define the shape and characteristics of data that can be passed to or returned from a model-defined function. For more information, see Function Element (CSDL).

The Property element can have exactly one of the following child elements:

The Property element can have any number child annotation 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 following table describes the attributes that can be applied to the Property element.

Attribute Name Is Required Value

Name

Yes

The name of the property.

Type

Yes

The type of the property value.

Nullable

No

True (the default value) or False depending on whether the property can have a null value.

Bb399546.note(en-us,VS.100).gifNote:
In the version of CSDL indicated by the https://schemas.microsoft.com/ado/2006/04/edm namespace, a complex type property must have Nullable="False".

DefaultValue

No

The default value of the property.

MaxLength

No

The maximum length of the property value.

FixedLength

No

True or False depending on whether the property value will be stored as a fixed length string.

Precision

No

The precision of the property value.

Scale

No

The scale of the property value.

Unicode

No

True or False depending on whether the property value will be stored as a Unicode string.

Collation

No

A string that specifies the collating sequence to be used in the data source.

Note

Any number of annotation attributes (custom XML attributes) may be applied to the Property 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 following example shows Property elements used to define the shape of the return type of a model-defined function.

<Function Name="LastNamesAfter">
  <Parameter Name="someString" Type="Edm.String" />
  <ReturnType>
   <CollectionType>
     <RowType>
       <Property Name="FirstName" Type="Edm.String" Nullable="false" />
       <Property Name="LastName" Type="Edm.String" Nullable="false" />
     </RowType>
   </CollectionType>
  </ReturnType>
  <DefiningExpression>
            SELECT VALUE ROW(p.FirstName, p.LastName)
            FROM SchoolEntities.People AS p
            WHERE p.LastName &gt;= somestring
  </DefiningExpression>
</Function>

See Also

Concepts

Entity Framework Overview
CSDL Specification
Schema Element (CSDL)
FunctionImport Element (CSDL)

Other Resources

CSDL, SSDL, and MSL Specifications
ADO.NET Entity Data Model Tools
property (Entity Data Model)
facet (Entity Data Model)