Question

I generate the metadata from the database following the http://www.breezejs.com/documentation/load-metadata-script My question is : How can I generate the metadata for two entities that has the same name but a different shema in the database ?

I tried to use a qualified name for my entities like this : ...

"entityType": [
      {
        "name": "Admin.RefactorColumn",
        "key": {
          "propertyRef": {
            "name": "Id"
          }
        },
        "property": [
          {
            "name": "Id",
            "type": "Edm.Int32",
            "nullable": "false",
            "annotation:StoreGeneratedPattern": "Identity"
          }, ...

... the problem is that when I make entityManager.saveChanges() and return the saveResult(also made by hand) from server breeze look for an entity with the name RefactorColumn:#Admin ... instead of Admin.RefactorColumn:#...

I have no issue if name is just "RefactorColumn" instead of "Admin.RefactorColumn"

Can I solve this issue changing the metadata format or the saveResult format ?

Thank for any help !

Was it helpful?

Solution

All breeze EntityTypes have a concept of a namespace qualified name. This name is a composition of a 'shortName' and a 'namespace'. As of breeze 1.4.16 a qualified name can be created by calling the EntityType.qualifyTypeName static function. i.e.

 var shortName = "Employee";
 var namespace = "My.Qualified.Namespace";
 var qualifiedName = breeze.EntityType.qualifyTypeName(shortName, namespace);
 // qualifiedTypeName will be => "Employee:#My.Qualified.Namespace"

In general, all breeze APIs will accept either a shortName OR a qualified name. If a shortName is provided then breeze will internally convert it to a qualified name by finding the first qualified name within the local metadataStore with a matching shortName.

Breeze metadata for each entity type can either be retrieved from a server or defined on the client. If defined on the client your entityType would be defined something like this:

myMetadataStore.addEntityType({
        shortName: "RefactorColumn",
        namespace: "Admin",
        autoGeneratedKeyType: breeze.AutoGeneratedKeyType.Identity,
        dataProperties: {
            id: { dataType: DataType.Int32, isPartOfKey: true, isNullable: false },
            // additional properties here:
        },
});

There are several examples of this technique in the DocCode sample in the breeze.js.samples GitHub repo.

Alternatively, if you are defining metadata by returning json from the server you have two options, you can either return a valid OData metadata definition ( which it appears to be what you are trying to return above) OR you can use breeze's native metadata format, which is MUCH simpler. The simplest way to see what this would look like is to create the metadata on the client as shown above and the call

var exportedMetadata = myMetadataStore.exportMetadata();

The contents of the exportedMetadata will be in 'native' breeze metadata format, which is basically just a jsonified version of the internal entityType definition.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top