0
votes

We are currently developing a small Hmtl/ JavaScript application with breeze.js (Version 1.3.4). We configured to used OData protocol to query the entities.

With a simple entity it just works fine. If we are querying a complex entity (contact entity with two complex type properties for phone numbers and addresses), we receive the following error:

"TypeError: Cannot call method '_createInstanceCore' of null
    at ctor.startTracking (<ServerAddress>/scripts/breeze.debug.js:14086:49)
    at Array.forEach (native)
    at ctor.startTracking (<ServerAddress>1/scripts/breeze.debug.js:14069:12)
    at new ctor <ServerAddress>/scripts/breeze.debug.js:2952:52)
    at proto._createEntityCore (<ServerAddress>1/scripts/breeze.debug.js:6478:9)
    at mergeEntity <ServerAddress>/scripts/breeze.debug.js:12458:39)
    at processMeta (<ServerAddress>/scripts/breeze.debug.js:12381:24)
    at visitAndMerge (<ServerAddress>/scripts/breeze.debug.js:12361:16)
    at <ServerAddress>/scripts/breeze.debug.js:12316:33
    at Array.map (native)
From previous event:
    at executeQueryCore (<ServerAddress>/scripts/breeze.debug.js:12290:77)
    at proto.executeQuery (<ServerAddress>/scripts/breeze.debug.js:11243:23)
    at DataContext.executeCachedQuery (<ServerAddress>/App/services/datacontext.js:138:33)
    at DataContext.getContactsBySearchParams (<ServerAddress>/App/services/datacontext.js:111:25)
    at Search.searchCmd.ko.asyncCommand.execute (<ServerAddress>/App/viewmodels/search.js:34:38)
    at Search.ko.asyncCommand.self.execute (<ServerAddress>/scripts/knockout.command.js:57:29)
    at HTMLButtonElement.ko.bindingHandlers.event.init (<ServerAddress>/scripts/knockout-2.2.1.debug.js:2318:66)"

While debugging the code, we see, that the dataType field of the complex property instance is null:

val = prop.dataType._createInstanceCore(entity, prop.name);

We can also see that the complexTypeName has a strange value formatting like:

<ComplexTypeName>):#<NameSpace>

Another thing we noticed concerning the strange complex type name is, that the entities property is a collection of complex types (a contact may have multiple addresses). The check on Line 14085 always returns isScalar = true, but a complex array should be created instead.

Is there a problem with the OData Metadata for complex types? How could we solve this issue?

Thank you in advance for your answer.

Cheers, Marc

2

2 Answers

0
votes

Breeze currently does support both scalar complex types and arrays of complex types.

But there is a bug with using EntityManager.createEntity to create an entity and its complex type values in a single pass. This will be fixed in the next release in about a week.

So for now the following does NOT work. ( Assume 'location' in the examples below is a complex property of type 'Location', itself with several other properties)

var supplier = em.createEntity("Supplier", 
   { companyName: "XXX", location: { city: "LA" } }
);

but the following will ( assuming you are using the breeze Angular/backingStore impl - the knockout code would look a bit different)

var supplier = em.createEntity("Supplier", { companyName: "XXX" });
supplier.location.city = "San Francisco";
supplier.location.postalCode = "91333";

or the following

var supplier = em.createEntity("Supplier", { companyName: "XXX" });
var locationType = em.metadataStore.getEntityType("Location");
supplier.location = locationType.createInstance(
   { city: "Boston", postalCode: "12345" }
);
0
votes

I am seeing the same problem with breeze 1.4.5. My metadata looks like:

{  "shortName":"Phone",
   ...
   "dataProperties":[ {"name":"phoneNumber", 
                    "complexTypeName":"PhoneNumber#mynamespace",
                    "isScalar":true }]
   ...
},
{"shortName":"PhoneNumber",
 "namespace":"mynamespace",
 "isComplexType":true,
 "dataProperties":[ ... ]
}

My client code makes a call:

var newPhone = manager.createEntity('Phone', {phoneNumber:{num: "234-2342"}});

(there are more properties in the PhoneNumber complex type, but you yet the picture). The breeze code (same call stack as orignal poster's) tries to dereference the dataType field, which is not defined, and throws an exception:

if (prop.isDataProperty) {
    if (prop.isComplexProperty) {
         if (prop.isScalar) {
               val = prop.dataType._createInstanceCore(entity, prop);
         } else {
               val = breeze.makeComplexArray([], entity, prop);
         }

I went through the Zza sample's schema and found no examples of complex data properties. The Northwind schema included with the samples bundle does, but I'm not sure how to get it to work with my schema.