Up Model
DevForce Resource Center » Development guide » Model » Examine model metadata

Examine model metadata

Last modified on September 14, 2012 19:20

DevForce maintains metadata about your model which you can examine at runtime by interrogating the EntityMetadata held in the EntityMetadataStore.


The EntityMetadataStore and EntityMetadata

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:

output_html_m56db1055.png

The table below provides an explanation for a few key members:

PropertyCanQueryByEntityKeyGets whether primary key queries are allowed.
PropertyComplexTypePropertiesReturns a collection of DataEntityProperties that describe complex object properties for entities of this type.
PropertyConcurrencyPropertiesReturns a collection of DataEntityProperties that are concurrency properties for entities of this type.
MethodCreateEntity()Creates a new entity of the type described by this metadata item.
PropertyDataPropertiesReturns a collection of DataEntityProperties for entities of this type.
PropertyDataSourceKeyNameGets the name of the Data Source Key associated with this type.
PropertyDefaultValueFunctionStatic - Use to override how DevForce sets the default value for a data entity property.
PropertyEntityPropertiesReturns a collection of EntityProperties that belong to entities of this type.
PropertyEntityTypeGets the type of the entity.
PropertyForeignKeyPropertiesReturns a collection of ForegnKey DataEntityProperties
PropertyHasStoreGeneratedIdReturns whether this entity type has a store generated id.
PropertyIsComplexObjectTypeReturns whether this metadata describes a ComplexObject.
PropertyKeyPropertiesReturns a collection of DataEntityProperties that are keys for entities of this type.
PropertyNavigationPropertiesReturns a collection of NavigationEntityProperties for entities of this type.

Property Metadata

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
Tags: Model Metadata
Created by DevForce on September 23, 2010 13:23

This wiki is licensed under a Creative Commons 2.0 license. XWiki Enterprise 3.2 - Documentation. Copyright © 2020 IdeaBlade