Why would the entityAspect of my query items be null?

breeze, edmx, javascript, sharepoint, typescript

Solution

If Breeze can't find a matching type in its metadata to what it receives as a result of a query, it simply returns the "raw" json object.

The reason that your metadata is not available is usually due to one of two explanations:

1) You are not serializing the type information in the query response. The [BreezeController] attribute or the [BreezeJsonFormatter] attributes both accomplish this.

2) The query itself is not returning types for which metadata was described. You can either create the metadata directly on the client in this case, or have it returned from the server via a "Metadata" method. ( see the NoDb example in the Breeze Zip package for an example of the first).

You can also look at the JsonResultsAdapter if you want to coerce any query result into a "known" metadata type, but this is generally not necessary if you are using the [BreezeController] attribute.

Hope this helps.

Problem

Working with breeze backed by SharePoint, as described here, and using TypeScript rather than JS. In a DataService class I create an EntityManager and execute a Query: ``` private servicePath: string = '/api/PATH/'; private manager: breeze.EntityManager; constructor() { this.init(); } private init(): void { this.manager = new breeze.EntityManager(this.servicePath); } public ListResponses(): breeze.Promise { var query = breeze.EntityQuery.from("Responses"); return this.manager.executeQuery(query); } ``` I then call this from my view model, which works fine: ``` private loadResponses(): void { this.dataservice.ListResponses().then((data) => { this.handleResponsesLoaded(data); }).fail((error) => { this.handleDataError(error); }); } private handleResponsesLoaded(data:any): void { for (var i = 0; i < results.length; i++){ this.extendItem(results[i]); } this.renderList(results, "#tp-responses-list"); } ``` But my attempt to extend each item fails, because the item's `entityAspect` is null: ``` private extendItem(item: any): void { item.entityAspect.propertyChanged.subscribe(() => { // FAILS HERE setTimeout(() => { if (item.entityAspect.entityState.isModified()) { this.dataservice.SaveChanges().then((result) => { tracer.Trace("SaveChanged Result: " + result); }).fail((error) => { this.handleDataError(error); }); } }, 0); }); } ``` Upon inspecting the result item, I can see it's just the plain data object, with all the properties I would expect but no Entity goodness: I've just started with breeze, so the best way to put the question is probably: what have I done wrong here?

Original source