breeze-client / EntityType
Class: EntityType
Defined in: src/metadata/entity-metadata.ts:1020
Container for all of the metadata about a specific type of Entity.
Constructors
Constructor
new EntityType(
config):EntityType
Defined in: src/metadata/entity-metadata.ts:1128
EntityType constructor
const entityType = new EntityType({
shortName: "person",
namespace: "myAppNamespace"
});Parameters
config
MetadataStore | EntityTypeConfig
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.
Returns
EntityType
Properties
autoGeneratedKeyType
autoGeneratedKeyType:
AutoGeneratedKeyType
Defined in: src/metadata/entity-metadata.ts:1074
The AutoGeneratedKeyType for this EntityType. Read Only
baseEntityType
baseEntityType:
EntityType
Defined in: src/metadata/entity-metadata.ts:1059
The base EntityType (if any) for this EntityType. Read Only
baseTypeName?
optionalbaseTypeName?:string
Defined in: src/metadata/entity-metadata.ts:1057
The name of this EntityType's base EntityType (if any)
complexProperties
complexProperties:
DataProperty[]
Defined in: src/metadata/entity-metadata.ts:1045
The DataProperties for this EntityType that contain instances of a ComplexType. Read Only
concurrencyProperties
concurrencyProperties:
DataProperty[]
Defined in: src/metadata/entity-metadata.ts:1043
The DataProperties associated with this EntityType that are concurrency properties. Read Only
custom?
optionalcustom?:any
Defined in: src/metadata/entity-metadata.ts:1082
A free form object that can be used to define any custom metadata for this EntityType. Read Only
dataProperties
dataProperties:
DataProperty[]
Defined in: src/metadata/entity-metadata.ts:1030
The DataProperties (see DataProperty associated with this EntityType. Read Only
defaultResourceName
defaultResourceName:
string
Defined in: src/metadata/entity-metadata.ts:1078
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 EntityAspect.loadNavigationProperty or when executing any EntityQuery that was created via an EntityKey. Read Only
foreignKeyProperties
foreignKeyProperties:
DataProperty[]
Defined in: src/metadata/entity-metadata.ts:1037
The DataProperties associated with this EntityType that are foreign key properties. Read Only
getEntityCtor
getEntityCtor: (
forceRefresh) => () =>StructuralObject
Defined in: src/metadata/entity-metadata.ts:1111
Returns the constructor for this EntityType.
Parameters
forceRefresh?
boolean = false
Whether to ignore any cached version of this constructor. (default == false)
Returns
The constructor for this EntityType.
() => StructuralObject
Deprecated
Use EntityType.getCtor instead.
initFn?
optionalinitFn?:string|Function
Defined in: src/metadata/entity-metadata.ts:1094
The function, or the name of a method on the entity, that is called with each entity of this type once it has been created and populated, whether by EntityType.createEntity or from query results. A base type's initFn runs first. Set from the initFn argument of MetadataStore.registerEntityTypeCtor; applications set it there rather than here.
inverseForeignKeyProperties
inverseForeignKeyProperties:
DataProperty[]
Defined in: src/metadata/entity-metadata.ts:1041
The foreign key DataProperties on other EntityTypes that refer to this EntityType. When an entity's key changes, such as when a temporary key is replaced on save, Breeze uses these to update the foreign keys of cached entities it cannot reach through a navigation property. Read Only
isAbstract
isAbstract:
boolean
Defined in: src/metadata/entity-metadata.ts:1065
Whether this EntityType is abstract. Read Only
isAnonymous
isAnonymous:
boolean
Defined in: src/metadata/entity-metadata.ts:1068
Whether this EntityType is anonymous. Anonymous types will never be communicated to or from the server. They are purely for client side use and are given an automatically generated name. Read Only
isComplexType
isComplexType:
boolean=false
Defined in: src/metadata/entity-metadata.ts:1026
Always false for an EntityType.
isFrozen
isFrozen:
boolean
Defined in: src/metadata/entity-metadata.ts:1071
Whether this EntityType has been 'frozen'. EntityTypes become frozen after the first instance of that type has been created and attached to an EntityManager.
keyProperties
keyProperties:
DataProperty[]
Defined in: src/metadata/entity-metadata.ts:1035
The DataProperties associated with this EntityType that make up it's EntityKey. Read Only
metadataStore
metadataStore:
MetadataStore
Defined in: src/metadata/entity-metadata.ts:1028
The MetadataStore that contains this EntityType. Read Only
name
name:
string
Defined in: src/metadata/entity-metadata.ts:1051
The fully qualified name of this EntityType. Read Only
namespace
namespace:
string
Defined in: src/metadata/entity-metadata.ts:1055
The namespace for this EntityType. Read Only
navigationProperties
navigationProperties:
NavigationProperty[]
Defined in: src/metadata/entity-metadata.ts:1032
The NavigationProperties (see NavigationProperty associated with this EntityType. Read Only
noTrackingFn?
optionalnoTrackingFn?:Function
Defined in: src/metadata/entity-metadata.ts:1099
The function that a query with EntityQuery.noTracking enabled calls for each result of this type, as noTrackingFn(node, entityType); its return value replaces the result. Set from the noTrackingFn argument of MetadataStore.registerEntityTypeCtor; applications set it there rather than here.
serializerFn?
optionalserializerFn?: (prop,val) =>any
Defined in: src/metadata/entity-metadata.ts:1080
A function that is used to customize the serialization of any EntityProperties of this type.
Parameters
prop
val
any
Returns
any
shortName
shortName:
string
Defined in: src/metadata/entity-metadata.ts:1053
The short, unqualified, name for this EntityType. Read Only
subtypes
subtypes:
EntityType[]
Defined in: src/metadata/entity-metadata.ts:1062
The EntityTypes that derive directly from this one. See EntityType.getSelfAndSubtypes for the whole hierarchy. Read Only
unmappedProperties
unmappedProperties:
DataProperty[]
Defined in: src/metadata/entity-metadata.ts:1048
The DataProperties associated with this EntityType that are not mapped to any backend datastore. These are effectively free standing properties. Read Only
validators
validators:
Validator[]
Defined in: src/metadata/entity-metadata.ts:1085
The entity level validators associated with this EntityType. Validators can be added and removed from this collection. Read Only.
warnings
warnings:
any[]
Defined in: src/metadata/entity-metadata.ts:1089
Not used by breeze-client 3: always an empty array. In 2.x the CSDL metadata parser recorded data types it did not recognize here; v3 reports them with console.warn instead.
Methods
addProperty()
addProperty(
property):void
Defined in: src/metadata/entity-metadata.ts:1253
Adds a DataProperty or a NavigationProperty to this EntityType.
// assume myEntityType is a newly constructed EntityType.
myEntityType.addProperty(dataProperty1);
myEntityType.addProperty(dataProperty2);
myEntityType.addProperty(navigationProperty1);Parameters
property
Returns
void
addValidator()
addValidator(
validator,property?):void
Defined in: src/metadata/entity-metadata.ts:1523
Adds either an entity or property level validator to this EntityType.
// assume em1 is an EntityManager containing a number of existing entities.
const custType = em1.metadataStore.getAsEntityType("Customer");
const countryProp = custType.getProperty("country");
const valFn = (v: string | null) => v == null || v.startsWith("US");
const 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);Parameters
validator
Validator to add.
property?
string | EntityProperty
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'.
Returns
void
clientPropertyPathToServer()
clientPropertyPathToServer(
propertyPath,delimiter?):string
Defined in: src/metadata/entity-metadata.ts:1644
Translates a client-side property path into the names the server uses, applying this type's NamingConvention to each segment: with the default camelCase convention, "company.companyName" becomes "Company.CompanyName". A UriBuilderAdapter uses it to write a query the server can read.
Parameters
propertyPath
string
a path of property names separated by .
delimiter?
string = '.'
what to join the server names with. Defaults to .
Returns
string
The same path in server terms.
createEntity()
createEntity<
T>(initialValues?):T
Defined in: src/metadata/entity-metadata.ts:1355
Creates a new entity of this type, detached: add it to a manager with EntityManager.addEntity, or use EntityManager.createEntity, which does both.
// assume em1 is an EntityManager containing a number of existing entities.
const custType = em1.metadataStore.getAsEntityType("Customer");
const cust1 = custType.createEntity<Customer>({ companyName: "Acme" }); // Customer
em1.addEntity(cust1);T is the type you expect back. Nothing checks it - an EntityType knows its metadata, not your class - and it defaults to any.
const order = custType.createEntity<Order>(); // compiles, but creates a CustomerType Parameters
T
T = any
Parameters
initialValues?
any
Property values to set immediately after creation.
Returns
T
The new entity.
getAllValidators()
getAllValidators():
Validator[]
Defined in: src/metadata/entity-metadata.ts:1234
Returns the entity level validators that apply to this type: its own EntityType.validators followed by those of each base type. Returns a new array, so changing it does not change the type.
Returns
getCtor()
getCtor(
forceRefresh?): () =>StructuralObject
Defined in: src/metadata/entity-metadata.ts:1435
Returns the constructor for this EntityType.
Parameters
forceRefresh?
boolean = false
Whether to ignore any cached version of this constructor. (default == false)
Returns
The constructor for this EntityType.
() => StructuralObject
getDataProperty()
getDataProperty(
propertyName):DataProperty
Defined in: src/metadata/entity-metadata.ts:1568
Returns a data property with the specified name or null.
// assume em1 is an EntityManager containing a number of existing entities.
const custType = em1.metadataStore.getAsEntityType("Customer");
const companyNameDataProp = custType.getDataProperty("companyName");Parameters
propertyName
string
Returns
A DataProperty or null if not found.
getEntityKeyFromRawEntity()
getEntityKeyFromRawEntity(
rawEntity,rawValueFn):EntityKey
Defined in: src/metadata/entity-metadata.ts:1665
Builds the EntityKey for an entity still in its raw server form, before it has been materialized. A DataServiceAdapter or JsonResultsAdapter uses it to find out whether the cache already holds the entity a node describes.
Parameters
rawEntity
any
the untyped node as it arrived from the server
rawValueFn
Function
reads one DataProperty off that node. It is given the node and the property, and is what knows whether the node is keyed by client or by server names
Returns
The key, with each value parsed into its property's DataType.
getNavigationProperty()
getNavigationProperty(
propertyName):NavigationProperty
Defined in: src/metadata/entity-metadata.ts:1581
Returns a navigation property with the specified name or null.
// assume em1 is an EntityManager containing a number of existing entities.
const custType = em1.metadataStore.getAsEntityType("Customer");
const customerOrdersNavProp = custType.getNavigationProperty("orders");Parameters
propertyName
string
Returns
A NavigationProperty or null if not found.
getProperties()
getProperties():
EntityProperty[]
Defined in: src/metadata/entity-metadata.ts:1543
Returns all of the properties ( dataProperties and navigationProperties) for this EntityType.
// assume em1 is an EntityManager containing a number of existing entities.
const custType = em1.metadataStore.getAsEntityType("Customer");
const arrayOfProps = custType.getProperties();Returns
An array of Data and Navigation properties.
getProperty()
getProperty(
propertyPath,throwIfNotFound?):EntityProperty|null
Defined in: src/metadata/entity-metadata.ts:1604
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.
const custType = em1.metadataStore.getAsEntityType("Customer");
const companyNameProp = custType.getProperty("companyName");This method can also walk a property path to return a property
const orderDetailType = em1.metadataStore.getAsEntityType("OrderDetail");
const companyNameProp2 = orderDetailType.getProperty("order.customer.companyName");
// companyNameProp === companyNameProp2Parameters
propertyPath
string
throwIfNotFound?
boolean = false
{Boolean} Whether to throw an exception if not found.
Returns
EntityProperty | null
A DataProperty or NavigationProperty or null if not found.
getPropertyNames()
getPropertyNames():
any[]
Defined in: src/metadata/entity-metadata.ts:1555
Returns all of the property names ( for both dataProperties and navigationProperties) for this EntityType.
// assume em1 is an EntityManager containing a number of existing entities.
const custType = em1.metadataStore.getAsEntityType("Customer");
const arrayOfPropNames = custType.getPropertyNames();Returns
any[]
getSelfAndSubtypes()
getSelfAndSubtypes():
EntityType[]
Defined in: src/metadata/entity-metadata.ts:1221
Returns an array containing this type and any/all subtypes of this type down thru the hierarchy.
Returns
EntityType[]
isSubtypeOf()
isSubtypeOf(
entityType):boolean
Defined in: src/metadata/entity-metadata.ts:1208
Returns whether this type is a subtype of a specified type.
Parameters
entityType
EntityType
Returns
boolean
setProperties()
setProperties(
config):void
Defined in: src/metadata/entity-metadata.ts:1193
General purpose property set method
// assume em1 is an EntityManager containing a number of existing entities.
const custType = em1.metadataStore.getAsEntityType("Customer");
custType.setProperties({
autoGeneratedKeyType: AutoGeneratedKeyType.Identity,
defaultResourceName: "CustomersAndIncludedOrders"
});Parameters
config
a configuration object
Returns
void
toJSON()
toJSON():
Object
Defined in: src/metadata/entity-metadata.ts:1762
Returns this type's metadata as a plain object in Breeze's native JSON metadata format, leaving out default values and empty arrays. Only the properties this type declares are included, not those it inherits from a base type. JSON.stringify calls it when MetadataStore.exportMetadata serializes the store.
Returns
Object
toString()
toString():
string
Defined in: src/metadata/entity-metadata.ts:1752
Returns a string representation of this EntityType.
Returns
string