DevForce maintains metadata about your model which you can examine at runtime by interrogating the EntityMetadata held in the EntityMetadataStore.
DevForce maintains a thread-safe repository of metadata for all types in a domain model. Applications can query the store using the GetEntityMetadata() method for a type:
C# | EntityMetadata employeeEntityMetaData = EntityMetadataStore.Instance.GetEntityMetadata( typeof(DomainModel.Employee)); |
VB | Dim employeeEntityMetaData As EntityMetadata = _ EntityMetadataStore.Instance.GetEntityMetadata( _ GetType(DomainModel.Employee)) |
You can also access the EntityMetadata for any entity instance using its EntityAspect:
C# | var cust = _em1.Customers.First(); var metadata = cust.EntityAspect.EntityMetadata; |
VB | Dim cust = _em1.Customers.First() Dim metadata = cust.EntityAspect.EntityMetadata |
The EntityMetadata provides the following members:
The table below provides an explanation for a few key members:
Property | CanQueryByEntityKey | Gets whether primary key queries are allowed. |
Property | ComplexTypeProperties | Returns a collection of DataEntityProperties that describe complex object properties for entities of this type. |
Property | ConcurrencyProperties | Returns a collection of DataEntityProperties that are concurrency properties for entities of this type. |
Method | CreateEntity() | Creates a new entity of the type described by this metadata item. |
Property | DataProperties | Returns a collection of DataEntityProperties for entities of this type. |
Property | DataSourceKeyName | Gets the name of the Data Source Key associated with this type. |
Property | DefaultValueFunction | Static - Use to override how DevForce sets the default value for a data entity property. |
Property | EntityProperties | Returns a collection of EntityProperties that belong to entities of this type. |
Property | EntityType | Gets the type of the entity. |
Property | ForeignKeyProperties | Returns a collection of ForegnKey DataEntityProperties |
Property | HasStoreGeneratedId | Returns whether this entity type has a store generated id. |
Property | IsComplexObjectType | Returns whether this metadata describes a ComplexObject. |
Property | KeyProperties | Returns a collection of DataEntityProperties that are keys for entities of this type. |
Property | NavigationProperties | Returns a collection of NavigationEntityProperties for entities of this type. |
When DevForce generates the code for your domain model it includes a nested class called PropertyMetadata within each generated Entity. Within PropertyMetadata are static fields for all the EntityProperty definitions within the entity. You’ll see a DataEntityProperty for every non-navigation property, and either a NavigationScalarEntityProperty or NavigationListEntityProperty for all navigation properties.
You can easily access these properties at any time via the static field definitions:
C# | var dataProp = Customer.PropertyMetadata.Id; var navListProp = Customer.PropertyMetadata.OrderSummaries; var navScalarProp = OrderSummary.PropertyMetadata.Customer; |
VB | Dim dataProp = Customer.PropertyMetadata.Id Dim navListProp = Customer.PropertyMetadata.OrderSummaries Dim navScalarProp = OrderSummary.PropertyMetadata.Customer |