Metadata API to support “custom” annotations.

This is a copy of the BreezeJS documentation on this subject. It will be updated for Breeze Sharp shortly. Meanwhile it may be suggestive.

  • The MetadataStore.importMetadata method supports “custom” nodes at the entity and property levels.

    1. Breeze native metadata may contain a single “custom” node for each EntityType, ComplexType, DataProperty or NavigationProperty node.
    2. A subset of Breeze native metadata format that only includes node “keys” and “custom” elements is also supported with the “allowMerge” parameter. (see example below) + This capability is ONLY supported if the “allowMerge” parameter to the importMetadata method is set to true. (The default is false). + The “key” for an EntityType or a ComplexType is the combination of the “namespace” and “shortName” nodes.
      • The “key” for a DataProperty or a NavigationProperty is just the “name” node ( and the fact that the property is embedded within an EntityType or ComplexType node.)
    3. “Custom” metadata may be any serializable javascript object. i.e. roundtripable via JSON.stringify and JSON.parse.)
  MetadataStore.proto.importMetadata = function (exportedMetadata, [allowMerge = false])
  • The MetadataStore.exportMetadata method will automatically include any custom metadata within the store.

  • The MetadataStore.addEntityType method supports “custom” nodes on both the entity and property level.

  • For the EntityType, ComplexType, DataProperty and NavigationProperty classes:

    1. All constructors accept a “custom” config node.
    2. The setProperties method accepts a “custom” config node.
    3. All custom metadata is accessible via a “custom” property.

Examples

Importing just custom metadata into an existing store.

	var customMetadata = {
        "structuralTypes": [{
            "shortName": "Customer",
            "namespace": "myNamespace",
            "dataProperties": [ { 
                "nameOnServer": "CustomerID",
                "custom": {                      
                    "description": "This customer's Id", 
                    "nestedDp": { 
                        "displayName": "Customer Id"
                    }
				}
            }, {
                "name": "companyName",
                "custom": {
                     "description": "The name of this company",
                     "moreInfo": {
                        hasServerValidation: true,
                        "defaultLocale": "en-gb"
 						 }
                }
            } ],
            "navigationProperties": [  {
                "name": "orders",
                "custom": {
				    "description": "The orders for this customer", navigation property",
                    "nestedNp": {
                        x: 3,
                        y: 4
                        z: 7
                    }						
                }  
            } ],
            "custom": {               
               "description": "A customer"
               "nestedXXX": {
				  jsonInterceptorName: "foo",
               }
            }
        }]
    };
    myEntityManager.metadataStore.importMetadata(customMetadata, true);

Calling MetadataStore.addEntityType with custom metadata.

This example assumes the existence of makeCustomTypeAnnot and makeCustomPropAnnot methods that each create a serializable javascript object.

 var store = new MetadataStore();
 var eto = {}
 eto.shortName = "type1";
 eto.namespace = "mod1";
 eto.dataProperties = new Array();
 eto.autoGeneratedKeyType = breeze.AutoGeneratedKeyType.Identity;
 eto.custom = makeCustomTypeAnnot("type1");
 var dpo = {};
 dpo.name = "id";
 dpo.dataType = breeze.DataType.Int32;
 dpo.isNullable = false;
 dpo.isPartOfKey = true;
 dpo.custom = makeCustomPropAnnot("id");
 var dp = new breeze.DataProperty(dpo);
 eto.dataProperties.push(dp);           
 var et = new breeze.EntityType(eto);
 store.addEntityType(et);

Using “custom” in the constructor’s config arg:

 var dp = new DataProperty({
    "name: "Id",
    "dataType": breeze.DataType.Int32,
    "isNullable" false,
    "isPartOfKey": true
    "custom" {
        "foo": "fooValue", 		             
        "bar": {
           x: 3,
           y: 14,
           canShow: true
        }  
    }
 });

Accessing custom metadata

 var customerType = myEntityManager.metadataStore.getEntityType("Customer")
 var customerCustomMetadata = customerType.custom;
 var companyNameProp = customerType.getProperty("companyName");
 var companyNameCustomMetadata = companyNameProp.custom;