Progress will discontinue Telerik Platform on May 10th, 2018. Learn more

Nesting Relation Expands

Nesting Relation Expands

Nesting allows you to expand fields from already expanded fields, using a chain of content type relations. For further information about nesting and its limitations, see Limitations and Design Considerations.

To demonstrate nesting, we'll use the data model from Introduction to Data Relations. The aim is to create a single request that takes an activity and the comments to that activity along with information about the comment author.

Here is an example on how to nest expand expressions with the .NET SDK:

ExpandDefinition commentsExpandDefinition = new ExpandDefinition("Comments.ActivityId", "Comments");
ExpandDefinition createdByExpandDefinition = new ExpandDefinition("CreatedBy", "Author");
commentsExpandDefinition.ChildExpandDefinition = createdByExpandDefinition;

var result = app.WorkWith().Data<Activity>().
        GetById(activityId).
        Expand(commentsExpandDefinition).
        ExecuteSync();

which will return the following result:

{
    Result: {
        "Text": "It is finally time for graduation! Good job everyone, we made it.",
        ...
        "Comments": [{
            "Comment": "Congratulations!",
            "ActivityId": "activityId",
            "Author": { // CreatedBy is now a resolved user
                "Username": "seth",
                ...
            },
            ...
        }, {
            "Comment": "Thanks :)",
            "ActivityId": "activityId",
            "Author": {
                "Username": "michael",
                ...
            },
            ...
        }]
    }
}

The JSON representation of the result is used only for better readability. The actual result is a IEnumerable<Activity> where each activity has a Likes property of type IEnumerable<User> and a Comments property of type IEnumerable<Comment>. Any comment instance has an Author property of type User. For correct deserialization, these properties must be defined on the client side.

Start a free trial Request a demo
Contact us: +1-888-365-2779
sales@telerik.com
Copyright © 2016-2017, Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved.