Reputation: 7449
In a app I'm developing I create some UI widgets that are generated based on breeze metadata and attributes on my classes and properties. So on the server I read the attributes, and add them on breeze's generated metadata. On the client, after I load the metadata I add those attributes on the type. An example of this (on the client, after the enriched metadata loads):
function finishMetadata(md) {
for (var i = 0; i < md.schema.entityType.length; i++) {
var et = md.schema.entityType[i];
var etype = manager.metadataStore.getEntityType(et.name);
//isExportable is a class attribute
etype.isExportable = et.isExportable;
for (var j = 0; j < et.property.length; j++) {
var p = et.property[j];
var prop = etype.getProperty(p.name);
//displayName is a property attribute
prop.displayName = p.displayName ? p.displayName : p.name;
}
}
}
with this, when I call manager.metadataStore.getEntityType(entityName)
, I get all the entityType data, including the properties and all the attributes I added on the server.
This worked fine until today. I have added inheritance (TPT) on some classes (Customer:Person) and since the generated metadata from the Customer entity does not have the Person properties, I cannot add them to the metadataStore type. When I call metadataStore.getEntityType
for Person
, I get all attributes, but when I call it for Customer
I do not get my custom attributes (and this is because on the code above Customer
does not list the parent Person
properties so I do not have the chance to plug in my custom attributes.
Anyway, this feels hacky and messy, even to explain it. So here we are, breeze its in version 1.4.7 and I wonder if there is an easier way of adding custom data to the metadata that would not break with TPT?
PS.: I know that I can hand-craft the metadata but I would like to stick with the default as much as possible to avoid problems with future changes. So, basically all metadata changes should be minimal and automatic, based on the classes.
Upvotes: 1
Views: 430
Reputation: 7449
Well, I ended up goind further down on the way I'm doing things. Instead of just use manager.metadataStore.getEntityType
to get the type data (which does not bring my custom metadata), I look if my entityType has a baseType and if it does, I load that base type data and merge it with the child class. In my case, basically I get the dataProperties of the Person
and use them instead of the dataProperties of the Customer
. It works but I still looking for a cleaner and simpler way of doing something like this.
Upvotes: 1