user3930676
user3930676

Reputation: 3

Error loading entities with a navigation property using custom metadata

I have the following implementation of a custom metadata scenario using the boiler plate with breeze.metadata-helper 1.0.7 and BreezeJS 1.4.16:

    function addFoo() {
        addType({
            shortName: 'Foo',
            dataProperties: {
                Id: { type: ID },
                BarId: { type: ID }
            },
            navigationProperties: {
                Bar: {
                    entityTypeName: 'Bar',
                    associationName: 'Foo_Bar',
                    foreignKeyNames: ['BarId']
                }
            }
        });
    }

    function addBar() {
        addType({
            shortName: 'Bar',
            dataProperties: {
                Id: { type: ID },
            }
        });
    }

Upon completion of query (provided below) execution i receive the following error: TypeError: newValue.getProperty is not a function.

    var query = breeze.EntityQuery.from('Foos').expand('Bar');
    manager.execute(query).catch(function(error) { });

HTTP response contains the following JSON:

    [{"Id":1,"BarId":2,"Bar":{"Id":2}}]

Though this query works fine if i replace foreignKeyNames: ['BarId'] with invForeignKeyNames: ['Id']. And still, in the latter case the navigation property Bar() of foo entity is not of entity type Bar but a simple javascript object.

The questions are:

1) Why the query with foreignKeyNames fails

2) Why foo.Bar() is not an entity of type Bar

Thanks.

Upvotes: 0

Views: 116

Answers (1)

Jay Traband
Jay Traband

Reputation: 17052

I think the issue is with how you are serializing the result of your query. Take a look at the JsonResultsAdapter documentation where it discusses how to handle references in the json payload. You may need a custom JsonResultsAdapter ( pretty easy to write once you understand the idea).

Upvotes: 1

Related Questions