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?
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.
The following answer is not mine, but OP's. It was posted in the question itself, while it should have an answer.
The problem was a namespace mismatch. I'm extracting metadata from an edmx generated by a Visual Studio service reference. This edmx uses the namespace of the service it is calling. My proxy objects reside in a different namespace. Breeze's entity lookup (even using the short name) is in the format Type#Namespace, and so I was getting no matches. I tweaked my custom BuildJsonMetadata method on the server to swap the namespaces and now I have properly decorated entities which work correctly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With