Partilhar via


Relationship.CreateAsync Method

Definition

Overloads

CreateAsync(AtlasRelationship, CancellationToken)

Create a new relationship between entities.

CreateAsync(RequestContent, RequestContext)

[Protocol Method] Create a new relationship between entities.

CreateAsync(AtlasRelationship, CancellationToken)

Source:
Relationship.cs

Create a new relationship between entities.

public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Analytics.Purview.DataMap.AtlasRelationship>> CreateAsync (Azure.Analytics.Purview.DataMap.AtlasRelationship atlasRelationship, System.Threading.CancellationToken cancellationToken = default);
abstract member CreateAsync : Azure.Analytics.Purview.DataMap.AtlasRelationship * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Azure.Response<Azure.Analytics.Purview.DataMap.AtlasRelationship>>
override this.CreateAsync : Azure.Analytics.Purview.DataMap.AtlasRelationship * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Azure.Response<Azure.Analytics.Purview.DataMap.AtlasRelationship>>
Public Overridable Function CreateAsync (atlasRelationship As AtlasRelationship, Optional cancellationToken As CancellationToken = Nothing) As Task(Of Response(Of AtlasRelationship))

Parameters

atlasRelationship
AtlasRelationship

Atlas relationship instance.

cancellationToken
CancellationToken

The cancellation token to use.

Returns

Exceptions

atlasRelationship is null.

Examples

This sample shows how to call CreateAsync.

Uri endpoint = new Uri("<https://my-service.azure.com>");
TokenCredential credential = new DefaultAzureCredential();
Relationship client = new DataMapClient(endpoint, credential).GetRelationshipClient();

AtlasRelationship atlasRelationship = new AtlasRelationship();
Response<AtlasRelationship> response = await client.CreateAsync(atlasRelationship);

This sample shows how to call CreateAsync with all parameters.

Uri endpoint = new Uri("<https://my-service.azure.com>");
TokenCredential credential = new DefaultAzureCredential();
Relationship client = new DataMapClient(endpoint, credential).GetRelationshipClient();

AtlasRelationship atlasRelationship = new AtlasRelationship
{
    Attributes =
    {
        ["key"] = BinaryData.FromObjectAsJson(new object())
    },
    TypeName = "<typeName>",
    LastModifiedTS = "<lastModifiedTS>",
    CreateTime = 1234L,
    CreatedBy = "<createdBy>",
    End1 = new AtlasObjectId
    {
        Guid = "<guid>",
        TypeName = "<typeName>",
        UniqueAttributes =
        {
            ["key"] = BinaryData.FromObjectAsJson(new object())
        },
    },
    End2 = default,
    Guid = "<guid>",
    HomeId = "<homeId>",
    Label = "<label>",
    ProvenanceType = 1234,
    Status = StatusAtlasRelationship.Active,
    UpdateTime = 1234L,
    UpdatedBy = "<updatedBy>",
    Version = 1234L,
};
Response<AtlasRelationship> response = await client.CreateAsync(atlasRelationship);

Applies to

CreateAsync(RequestContent, RequestContext)

Source:
Relationship.cs

[Protocol Method] Create a new relationship between entities.

public virtual System.Threading.Tasks.Task<Azure.Response> CreateAsync (Azure.Core.RequestContent content, Azure.RequestContext context = default);
abstract member CreateAsync : Azure.Core.RequestContent * Azure.RequestContext -> System.Threading.Tasks.Task<Azure.Response>
override this.CreateAsync : Azure.Core.RequestContent * Azure.RequestContext -> System.Threading.Tasks.Task<Azure.Response>
Public Overridable Function CreateAsync (content As RequestContent, Optional context As RequestContext = Nothing) As Task(Of Response)

Parameters

content
RequestContent

The content to send as the body of the request.

context
RequestContext

The request context, which can override default behaviors of the client pipeline on a per-call basis.

Returns

The response returned from the service.

Exceptions

content is null.

Service returned a non-success status code.

Examples

This sample shows how to call CreateAsync and parse the result.

Uri endpoint = new Uri("<https://my-service.azure.com>");
TokenCredential credential = new DefaultAzureCredential();
Relationship client = new DataMapClient(endpoint, credential).GetRelationshipClient();

using RequestContent content = RequestContent.Create(new object());
Response response = await client.CreateAsync(content);

JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement;
Console.WriteLine(result.ToString());

This sample shows how to call CreateAsync with all request content and parse the result.

Uri endpoint = new Uri("<https://my-service.azure.com>");
TokenCredential credential = new DefaultAzureCredential();
Relationship client = new DataMapClient(endpoint, credential).GetRelationshipClient();

using RequestContent content = RequestContent.Create(new
{
    attributes = new
    {
        key = new object(),
    },
    typeName = "<typeName>",
    lastModifiedTS = "<lastModifiedTS>",
    createTime = 1234L,
    createdBy = "<createdBy>",
    end1 = new
    {
        guid = "<guid>",
        typeName = "<typeName>",
        uniqueAttributes = new
        {
            key = new object(),
        },
    },
    guid = "<guid>",
    homeId = "<homeId>",
    label = "<label>",
    provenanceType = 1234,
    status = "ACTIVE",
    updateTime = 1234L,
    updatedBy = "<updatedBy>",
    version = 1234L,
});
Response response = await client.CreateAsync(content);

JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement;
Console.WriteLine(result.GetProperty("attributes").GetProperty("<key>").ToString());
Console.WriteLine(result.GetProperty("typeName").ToString());
Console.WriteLine(result.GetProperty("lastModifiedTS").ToString());
Console.WriteLine(result.GetProperty("createTime").ToString());
Console.WriteLine(result.GetProperty("createdBy").ToString());
Console.WriteLine(result.GetProperty("end1").GetProperty("guid").ToString());
Console.WriteLine(result.GetProperty("end1").GetProperty("typeName").ToString());
Console.WriteLine(result.GetProperty("end1").GetProperty("uniqueAttributes").GetProperty("<key>").ToString());
Console.WriteLine(result.GetProperty("end2").GetProperty("guid").ToString());
Console.WriteLine(result.GetProperty("end2").GetProperty("typeName").ToString());
Console.WriteLine(result.GetProperty("end2").GetProperty("uniqueAttributes").GetProperty("<key>").ToString());
Console.WriteLine(result.GetProperty("guid").ToString());
Console.WriteLine(result.GetProperty("homeId").ToString());
Console.WriteLine(result.GetProperty("label").ToString());
Console.WriteLine(result.GetProperty("provenanceType").ToString());
Console.WriteLine(result.GetProperty("status").ToString());
Console.WriteLine(result.GetProperty("updateTime").ToString());
Console.WriteLine(result.GetProperty("updatedBy").ToString());
Console.WriteLine(result.GetProperty("version").ToString());

Applies to