Lazy loading

Entities have the option to lazy load properties and relations. Although there is support for this, always try to load the necessary members using the right load configuration and load options. This reduces overhead.

However, sometimes entities are passed between components and the required members might not be there. In these situations, lazy loading is a valid use case.

When the user lazy loads a member, the member is fetched from the server by doing some IO. Then the member is added to the entity instance.

To lazy load one or more members, there is always a required call to the server. Try to group as many lazy loading as possible in one go (see below).

Note that lazy loading always checks if the members are already present, and if they are no IO will be done. The SDK will never overwrite loaded members, only add members that are not loaded.

Preconditions

To be able to lazy load members, the entity must exist in M. There is no point in the user trying to lazy load members on an entity instance they have just created, since there are no missing members anyway.

Lazy loading a single member

To lazy load and return a property:

RequestResponse

IProperty titleProperty = await entity.GetPropertyAsync("Title");

To lazy load a property and return its value directly:

RequestResponse

string title = await titleProperty.GetPropertyValueAsync <string> ("Title"));

To lazy load and return a relation:

RequestResponse

IRelation relation = await entity.GetRelationAsync("AssetTypeToAsset");

Note

There are many more overloads for loading properties and relations. See the API Reference for a complete overview.

Lazy loading multiple members

To lazy load multiple properties in one call:

RequestResponse

var propertyLoadOption = new PropertyLoadOption("propertyName1", "propertyName2");
await entity.LoadPropertiesAsync(propertyLoadOption);

To lazy load multiple relations in one call:

RequestResponse

var relationLoadOption = new RelationLoadOption("relationName1", "relationName2");
await entity.LoadRelationsAsync(relationLoadOption);

To lazy load multiple both properties and relations in one call:

RequestResponse

var propertyLoadOption = new PropertyLoadOption("propertyName1", "propertyName2");
var relationLoadOption = new RelationLoadOption("relationName1", "relationName2");
await entity.LoadMembersAsync(propertyLoadOption, relationLoadOption);

Do you have some feedback for us?

If you have suggestions for improving this article,