0
votes

the following code will often run out of stack space because the type Entity has a property named EntityAspect, which has a property named Entity of type Entity which points to the owning Entity. This recursive definition causes several tools to fail or run incredibly slow, but most notably, knockout. Can anything be done to address this?

var custType = _this.metadataStore.getEntityType("Customer");
var cust1 = custType.createEntity();
var js = ko.toJS(cust1);
2

2 Answers

0
votes

I haven't actually tried this yet but I think you can do this

var js = ko.mapping.toJS(cust1, {
    ignore: ['entityAspect']
});
0
votes

I found I needed to ignore both entityAspect and entityType (snippet from custom datasource kendo datasource):

            this.entityManager.executeQuery(query)
            .then(function (xhr) {
                if (self.autoMapToJS) { // Breeze entities contain recursive properties (ugh!) - eliminate those
                    payload.data = ko.mapping.toJS(xhr.results, {
                        ignore: ['entityAspect', 'entityType']
                    });
                } else {
                    payload.data = xhr.results;
                }
                if (self.inlineCount) {
                    payload.total = xhr.inlineCount;
                }
                options.success(payload); // notify the DataSource that the operation is complete
            })
            .fail(function (rejected) {
                payload.error = rejected;
            })
            .done(); // terminate chain of promises
    }

In particular, trying to use with grids (wijmo & kendo), I was forced to map breeze data or enjoy stackoverflows as those controls would iterate through the properties.