Partilhar via


EntityType Element (CSDL)

The EntityType element represents the structure of a top-level concept, such as a customer or order, in a conceptual model. An entity type is a template for instances of entity types in an application. Each template contains the following information:

  • A unique name. (Required.)

  • An entity key that is defined by one or more properties. (Required.)

  • Properties for containing data. (Optional.)

  • Navigation properties that allow for navigation from one end of an association to the other end. (Optional.)

In an application, an instance of an entity type represents a specific object (such as a specific customer or order). Each instance of an entity type must have a unique entity key within an entity set.

Two entity type instances are considered equal only if they are of the same type and the values of their entity keys are the same.

An EntityType element can have the following child elements (in the order listed):

Applicable Attributes

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

Attribute Name Is Required Value

Name

Yes

The name of the entity type.

BaseType

No

The name of another entity type that is the base type of the entity type that is being defined.

Abstract

No

True or False, depending on whether the entity type is an abstract type.

OpenType

No

True or False depending on whether the entity type is an open entity type.

Bb399206.note(en-us,VS.100).gifNote:
The OpenType attribute is only applicable to entity types that are defined in conceptual models that are used with ADO.NET Data Services.

Note

Any number of annotation attributes (custom XML attributes) may be applied to the EntityType 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 and two NavigationProperty 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>

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 type (Entity Data Model)