Show:

EntityType Class

Container for all of the metadata about a specific type of Entity.

Methods

<ctor> EntityType

(
  • config
)

Parameters:

  • config Object | MetadataStore

    Configuration settings or a MetadataStore. If this parameter is just a MetadataStore then what will be created is an 'anonymous' type that will never be communicated to or from the server. It is purely for client side use and will be given an automatically generated name. Normally, however, you will use a configuration object.

    • shortName String
    • [namespace=""] String optional
    • [baseTypeName] String optional
    • [isAbstract=false] Boolean optional
    • [autoGeneratedKeyType] AutoGeneratedKeyType optional
    • [defaultResourceName] String optional
    • [dataProperties] Array of DataProperties optional
    • [navigationProperties] Array of NavigationProperties optional
    • [serializerFn] optional

      A function that is used to mediate the serialization of instances of this type.

    • [custom] Object optional

Example:

var entityType = new EntityType( {
    shortName: "person",
    namespace: "myAppNamespace"
    });

addProperty

(
  • property
)

Adds a DataProperty or a NavigationProperty to this EntityType.

Parameters:

Example:

// assume myEntityType is a newly constructed EntityType. 
myEntityType.addProperty(dataProperty1);
myEntityType.addProperty(dataProperty2);
myEntityType.addProperty(navigationProperty1);

addValidator

(
  • validator
  • [property]
)

Adds either an entity or property level validator to this EntityType.

Parameters:

  • validator Validator

    Validator to add.

  • [property] Object optional

    Property to add this validator to. If omitted, the validator is assumed to be an entity level validator and is added to the EntityType's 'validators'.

Example:

// assume em1 is an EntityManager containing a number of existing entities.
var custType = em1.metadataStore.getEntityType("Customer");
var countryProp = custType.getProperty("Country");
var valFn = function (v) {
    if (v == null) return true;
    return (core.stringStartsWith(v, "US"));
};
var countryValidator = new Validator("countryIsUS", valFn, 
    { displayName: "Country", messageTemplate: "'%displayName%' must start with 'US'" });
custType.addValidator(countryValidator, countryProp);

This is the same as adding an entity level validator via the 'validators' property of DataProperty or NavigationProperty

countryProp.validators.push(countryValidator);

Entity level validators can also be added by omitting the 'property' parameter.

custType.addValidator(someEntityLevelValidator);

or

custType.validators.push(someEntityLevelValidator);

createEntity

(
  • [initialValues]
)
Entity

Create a new entity of this type.

Parameters:

  • [initialValues] Config object optional
    • Configuration object of the properties to set immediately after creation.

Returns:

Entity:

The new entity.

Example:

// assume em1 is an EntityManager containing a number of existing entities.
var custType = em1.metadataStore.getEntityType("Customer");
var cust1 = custType.createEntity();
em1.addEntity(cust1);

getCtor ( or obsolete getEntityCtor)

() Function

Returns the constructor for this EntityType.

Returns:

Function:

The constructor for this EntityType.

getDataProperty

(
  • propertyName
)
DataProperty

Returns a data property with the specified name or null.

Parameters:

  • propertyName String

Returns:

DataProperty:

Will be null if not found.

Example:

// assume em1 is an EntityManager containing a number of existing entities.
var custType = em1.metadataStore.getEntityType("Customer");
var customerNameDataProp = custType.getDataProperty("CustomerName");

getNavigationProperty

(
  • propertyName
)
NavigationProperty

Returns a navigation property with the specified name or null.

Parameters:

  • propertyName String

Returns:

NavigationProperty:

Will be null if not found.

Example:

// assume em1 is an EntityManager containing a number of existing entities.
var custType = em1.metadataStore.getEntityType("Customer");
var customerOrdersNavProp = custType.getDataProperty("Orders");

getProperties

() Array of DataProperty | NavigationProperty

Returns all of the properties ( dataProperties and navigationProperties) for this EntityType.

Returns:

Array of DataProperty | NavigationProperty:

Array of Data and Navigation properties.

Example:

// assume em1 is an EntityManager containing a number of existing entities.
var custType = em1.metadataStore.getEntityType("Customer");
var arrayOfProps = custType.getProperties();

getProperty

(
  • propertyPath
  • [throwIfNotFound=false]
)
DataProperty | NavigationProperty

Returns either a DataProperty or a NavigationProperty with the specified name or null.

This method also accepts a '.' delimited property path and will return the 'property' at the end of the path.

Parameters:

  • propertyPath String
  • [throwIfNotFound=false] Boolean optional

    Whether to throw an exception if not found.

Returns:

DataProperty | NavigationProperty:

Will be null if not found.

Example:

var custType = em1.metadataStore.getEntityType("Customer");
var companyNameProp = custType.getProperty("CompanyName");

This method can also walk a property path to return a property

var orderDetailType = em1.metadataStore.getEntityType("OrderDetail");
var companyNameProp2 = orderDetailType.getProperty("Order.Customer.CompanyName");
// companyNameProp === companyNameProp2 

getPropertyNames

() Array of String

Returns all of the property names ( for both dataProperties and navigationProperties) for this EntityType.

Returns:

Array of String:

Example:

// assume em1 is an EntityManager containing a number of existing entities.
var custType = em1.metadataStore.getEntityType("Customer");
var arrayOfPropNames = custType.getPropertyNames();

getSelfAndSubtypes

()

Returns an array containing this type and any/all subtypes of this type down thru the hierarchy.

isSubtypeOf

(
  • entityType
)

Returns whether this type is a subtype of a specified type.

Parameters:

  • entityType Object

    [EntityType]

setProperties

(
  • config
)

General purpose property set method

Parameters:

  • config Object

    [object]

    • [autogeneratedKeyType] AutoGeneratedKeyType optional
    • [defaultResourceName] String optional
    • [serializerFn] optional

      A function that is used to mediate the serialization of instances of this type.

    • [custom] Object optional

Example:

// assume em1 is an EntityManager containing a number of existing entities.
var custType = em1.metadataStore.getEntityType("Customer");
custType.setProperties( {
    autoGeneratedKeyType: AutoGeneratedKeyType.Identity;
    defaultResourceName: "CustomersAndIncludedOrders"
)};

toString

() String

Returns a string representation of this EntityType.

Returns:

String:

Properties

autoGeneratedKeyType

AutoGeneratedKeyType

The AutoGeneratedKeyType for this EntityType.

readOnly

Default: AutoGeneratedKeyType.None

baseEntityType

EntityType

The base EntityType (if any) for this EntityType.

readOnly

complexProperties

Array of DataProperty

The DataProperties for this EntityType that contain instances of a ComplexType (see ComplexType).

readOnly

concurrencyProperties

Array of DataProperty

The DataProperties associated with this EntityType that are concurrency properties.

readOnly

custom

Object

A free form object that can be used to define any custom metadata for this EntityType.

readOnly

dataProperties

Array of DataProperty

The DataProperties (see DataProperty) associated with this EntityType.

readOnly

defaultResourceName

String

The default resource name associated with this EntityType. An EntityType may be queried via a variety of 'resource names' but this one is used as the default when no resource name is provided. This will occur when calling loadNavigationProperty or when executing any EntityQuery that was created via an EntityKey.

readOnly

foreignKeyProperties

Array of DataProperty

The DataProperties associated with this EntityType that are foreign key properties.

readOnly

isAbstract

Boolean

Whether this EntityType is abstract.

readOnly

keyProperties

Array of DataProperty

The DataProperties associated with this EntityType that make up it's EntityKey.

readOnly

metadataStore

MetadataStore

The MetadataStore that contains this EntityType

readOnly

name

String

The fully qualified name of this EntityType.

readOnly

namespace

String

The namespace for this EntityType.

readOnly

navigationProperties

Array of NavigationProperty

The NavigationProperties (see NavigationProperty) associated with this EntityType.

readOnly

shortName

String

The short, unqualified, name for this EntityType.

readOnly

unmappedProperties

Array of DataProperty

The DataProperties associated with this EntityType that are not mapped to any backend datastore. These are effectively free standing properties.

readOnly

validators

Array of Validator

The entity level validators associated with this EntityType. Validators can be added and removed from this collection.

readOnly