Search code examples
odatajaydata

Jaydata - support for polymorphic collections in OData v4


Does JayData 1.5.1 support polymorphic collections that can contain elements with an inheritance hierarchy?

I have an OData v4 service that contains a polymorphic collection. The service is implemented using asp.net WebApi 2.2 and OData 5.8. The collection contains appropriate $odata.type metadata that indicates the derived type, and the service itself appears to work as expected.

I have declared an entity base type and derived types in my data model, and the collection is declared in the data context as a collection with elementType set to the base entity type.

When querying this collection, it appears that JayData creates only the base type entity for each member of the collection, ignoring the $odata.type metatdata. Is there a way to instruct JayData to create appropriate derived entity types for the polymorphic collection?

Also, and related to the above, when I query the collection I need to expand a child collection of elements that are related only to one of the derived types, and not to the base type. In OData this is done using $expand similar to the following:

$expand=My.Model.DerivedType/ChildCollection

Is there a way to add this to the JayData 'include' part of the query?

Here's a sample data model that is somewhat representative:

    types["My.Model.BaseType"] = $data.Entity.extend("My.Model.BaseType", {
...
});
    types["My.Model.Child"] = $data.Entity.extend("My.Model.Child", {
...
});
    types["My.Model.DerivedType"] = types["My.Model.BaseType"].extend("My.Model.DerivedType", {
...
        ChildCollection: {
            "type": "Array",
            "elementType": "My.Model.Child",
            "inverseProperty": "$$unbound"
        }
});

exports.type = types["MyData.Container"] = $data.EntityContext.extend("MyData.Container", {

        PolymorphicCollection: {
            "type": "$data.EntitySet",
            "elementType": "My.Model.BaseType"
        },
});

Thanks,

Jeff.


Solution

  • Disclaimer: I work with the JayData team

    Inherited classes could not get into 1.5. The metadata model and the expression parser does support it but the query builder is not aware of classes and subclasses. Since inheritance is the bases for the Microsoft Graph API - we decided to dedicate the next version (1.6) to it - and not hold up on the release for the other V4 features.