Share via


DigitalTwinsClient.CreateModelsAsync Method

Definition

Creates one or many models asynchronously.

public virtual System.Threading.Tasks.Task<Azure.Response<Azure.DigitalTwins.Core.DigitalTwinsModelData[]>> CreateModelsAsync (System.Collections.Generic.IEnumerable<string> dtdlModels, System.Threading.CancellationToken cancellationToken = default);
abstract member CreateModelsAsync : seq<string> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Azure.Response<Azure.DigitalTwins.Core.DigitalTwinsModelData[]>>
override this.CreateModelsAsync : seq<string> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Azure.Response<Azure.DigitalTwins.Core.DigitalTwinsModelData[]>>
Public Overridable Function CreateModelsAsync (dtdlModels As IEnumerable(Of String), Optional cancellationToken As CancellationToken = Nothing) As Task(Of Response(Of DigitalTwinsModelData()))

Parameters

dtdlModels
IEnumerable<String>

The set of models conforming to Digital Twins Definition Language (DTDL) v2 to create. Each string corresponds to exactly one model.

cancellationToken
CancellationToken

The cancellation token.

Returns

The created models and the HTTP response Response<T>.

Exceptions

The exception that captures the errors from the service. Check the ErrorCode and Status properties for more details.

Examples

await client.CreateModelsAsync(new[] { newComponentModelPayload, newModelPayload });
Console.WriteLine($"Created models '{componentModelId}' and '{sampleModelId}'.");

Remarks

Bulk model creation is useful when several models have references to each other. It simplifies creation for the client because otherwise the models would have to be created in a very specific order. The service evaluates all models to ensure all references are satisfied, and then accepts or rejects the set. So using this method, model creation is transactional.

For more samples, see our repo samples.

Understand twin models in Azure Digital Twins.

Applies to

See also