Getting a Subset of Fields

Getting a Subset of Fields

When you read data from Telerik Platform, you can choose to receive only a subset of all available fields for each item. This saves bandwidth and can improve your app performance because data is fetched from the server faster. By default, all fields are returned from the server.

Specifics

The Id field is always returned by the server. In order to omit it you need to exclude it explicitly from the projection.

You cannot use inclusion and exclusion definitions simultaneously besides the case when you are including fields and excluding the Id field.

Including Fields

To project only a subset of fields to the result, you need to pass them to the IncludeFields method.

The following method will return only the specified fields:

public async Task GetActivitesAsync(EverliveApp app)
{
    var activities = await app.WorkWith().Data<Activity>().Get().
    IncludeFields(a => new { a.Text, a.CreatedAt }).ExecuteAsync();
}

Excluding Fields

Alternatively, you can specify which fields to exclude, by passing an anonymous function expression to the ExcludeFields method.

The following method will return all, but the specified fields.

public async Task GetActivitesAsync(EverliveApp app)
{
    var activities = await app.WorkWith().Data<Activity>().Get()
    .ExcludeFields(a => new { a.ModifiedAt, a.Owner }).ExecuteAsync();
}

Including Fields and Excluding the Id

The following snippet is the only case when the simultaneous usage is allowed:

public async Task GetActivitesAsync(EverliveApp app)
{
    var activities = await app.WorkWith().Data<Activity>().Get()
    .IncludeFields(a => new { a.Text, a.CreatedAt }).ExcludeFields(a => a.Id).ExecuteAsync();
}
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.