Properties are the fundamental building blocks of entity types and complex types. Properties 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 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.
|Properties, as described in this topic, are different from navigation properties. For more information, see navigation properties.|
A property definition contains the following information:
A property name. (Required)
A property type. (Required)
A set of facets. (Optional)
A property can contain primitive data (such as a string, an integer, or a Boolean value), or structured data (such as a complex type). Properties that are of primitive type are also called scalar properties. For more information, see Entity Data Model: Primitive Data Types.
|A complex type can, itself, have properties that are complex types.|
The diagram below shows a conceptual model with three entity types: Book, Publisher, and Author. Each entity type has several properties, although type information for each property is not conveyed in the diagram. Properties that are entity keys are denoted with (Key).
The ADO.NET Entity Framework uses a domain-specific language (DSL) called conceptual schema definition language (CSDL) to define conceptual models. The following CSDL defines the Book entity type (as shown in the diagram above) and indicates the type and name of each property by using XML attributes. An optional facet, Nullable, is also defined by using an XML attribute.
<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>
It is possible that one of the properties shown in the diagram is a complex type property. For example, the Address property on the Publisher entity type could be a complex type property composed of several scalar properties, such as StreetAddress, City, StateOrProvince, Country, and PostalCode. The CSDL representation of such a complex type would be as follows:
<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>