Editar

Compartilhar via


Web API EntityTypes

Within the CSDL $metadata document, immediately below the Service namespace there's a list of EntityTypes. An entity type is a named structured type with a key. It defines the named properties and relationships of a table.

EntityType elements usually have the following attributes:

Attribute Description
Name The name of the type; the LogicalName for the table.
BaseType The EntityType that the type inherits from.

For example, this XML element is the EntityType for the account entity, excluding properties and navigation properties.

<EntityType Name="account" BaseType="mscrm.crmbaseentity">  
  <Key>  
    <PropertyRef Name="accountid" />  <!--The name of the primary key --> 
  </Key>  
  <!--Properties and navigation properties removed for brevity-->  
  <Annotation Term="Org.OData.Core.V1.Description" String="Business that represents a customer or potential customer. The company that is billed in business transactions." />  
</EntityType>  

Except for three exceptions, all entity types have the following child elements:

Element Description
Key Contains a <PropertyRef> element where the Name attribute represents the primary key for the table.
Property Contains details about a property of the EntityType. See Web API Properties.
NavigationProperty Contains details about a relationship with this EntityType. See Web API Navigation Properties

Special entity types

There are three entity types that don't have Key, Property, or NavigationProperty elements.

crmbaseentity

This element defines a common abstract type for any table that contains business data.

<EntityType Name="crmbaseentity" Abstract="true" />

Because all entity types that contain business data inherit from crmbaseentity, crmbaseentity is referenced when a value isn't specific to one table.

expando

This element defines an entity type that inherits from crmbaseentity but is also an OData OpenType.

<EntityType Name="expando" BaseType="mscrm.crmbaseentity" OpenType="true" />

An expando entity type can be used as a parameter to an action, or as a response property from a function or action.

More information: Use open types with custom APIs

crmmodelbaseentity

This element exists near the bottom of the $metadata document:

<EntityType Name="crmmodelbaseentity" Abstract="true" />

This element defines a common abstract type for any schema definitions. It's the base type for another abstract base class used for table definitions. Unless you want to create and modify tables, columns, and relationships using Web API you don't need to use entity types that inherit from this type. More information: Use the Web API with table definitions.

EntityType inheritance

For business data, there are two more abstract entity types that inherit from crmbaseentity:

EntityType Description
principal systemuser and team entity types inherit from the principal entity type. Principal provides only the ownerid property, which every user-owned table has. This inheritance is what allows for user-owned records to be assigned to either a user or a team.

The ownerid property is the primary key for both systemuser and team EntityTypes.
activitypointer Any table that is configured as an activity inherits from the activitypointer entity type. This type provides common properties found in entity types such as: appointment, email, fax, letter, phonecall, and task. You can also create a custom table that represents an activity. These common properties make it possible to retrieve a list of activities of different types using these common properties

The activityid property is the primary key for all entity types that inherit from activitypointer.

When working with table definitions, there another hierarchy of inheritance. MetadataBase entity type inherits from the abstract crmmodelbaseentity to provide common MetadataId and HasChanged properties. More information: Use the Web API with table definitions.

Alternate Keys

When an entity type has any alternate keys defined, there's an Annotation that describes the properties that are involved in the alternate key definition.

The following example shows the annotation when the account entity has been configured to enable the accountnumber property as an alternate key.

<Annotation Term="OData.Community.Keys.V1.AlternateKeys">
    <Collection>
        <Record Type="OData.Community.Keys.V1.AlternateKey">
            <PropertyValue Property="Key">
                <Collection>
                    <Record Type="OData.Community.Keys.V1.PropertyRef">
                        <PropertyValue Property="Alias" String="accountnumber" />
                        <PropertyValue Property="Name" PropertyPath="accountnumber" />
                    </Record>
                </Collection>
            </PropertyValue>
        </Record>
    </Collection>
</Annotation>

More information: Retrieve record using an alternate key

Next steps

Learn about properties.

See also

Web API types and operations
Web API Service Documents
Web API Properties
Web API Navigation Properties
Web API Actions
Web API Functions
Web API Complex and Enumeration types
Use the Dataverse Web API