次の方法で共有


UniqueKeyPolicy クラス

定義

Azure Cosmos DB サービスのコレクション内のドキュメントに対して一意性制約を指定するための一意キー ポリシー構成を表します。

[System.Text.Json.Serialization.JsonConverter(typeof(Azure.Cosmos.TextJsonUniqueKeyPolicyConverter))]
public sealed class UniqueKeyPolicy
[<System.Text.Json.Serialization.JsonConverter(typeof(Azure.Cosmos.TextJsonUniqueKeyPolicyConverter))>]
type UniqueKeyPolicy = class
Public NotInheritable Class UniqueKeyPolicy
継承
UniqueKeyPolicy
属性

var collectionSpec = new DocumentCollection { Id = "Collection with unique keys", UniqueKeyPolicy = new UniqueKeyPolicy { UniqueKeys = new Collection<UniqueKey> { // pair </name/first, name/last> is unique. new UniqueKey { Paths = new Collection<string> { "/name/first", "/name/last" } }, // /address is unique. new UniqueKey { Paths = new Collection<string> { "/address" } }, } } };DocumentCollection コレクション = await クライアント。CreateDocumentCollectionAsync(databaseLink, collectionSpec });

var doc = JObject.Parse("{"name": { "first": "John", "last": "Smith" }, "alias":"johnsmith" }");await クライアント。CreateDocumentAsync(collection.SelfLink,doc);

doc = JObject.Parse("{"name": { "first": "James", "last": "Smith" }, "alias":"jamessmith" }");await クライアント。CreateDocumentAsync(collection.SelfLink,doc);

try { // Error: first+last name is not unique. doc = JObject.Parse("{"name": { "first": "John", "last": "Smith" }, "alias":"johnsmith1" }");await クライアント。CreateDocumentAsync(collection.SelfLink,doc);throw new Exception("CreateDocumentAsync should have throw exception/conflict");} catch (DocumentClientException ex) { if (ex.StatusCode != System.Net.HttpStatusCode.Conflict) がスローされます。}

try { // Error: alias is not unique. doc = JObject.Parse("{"name": { "first": "James Jr", "last": "Smith" }, "alias":"jamessmith" }");await クライアント。CreateDocumentAsync(collection.SelfLink,doc);throw new Exception("CreateDocumentAsync should have throw exception/conflict");} catch (DocumentClientException ex) { if (ex.StatusCode != System.Net.HttpStatusCode.Conflict) がスローされます。}

コンストラクター

UniqueKeyPolicy()

Azure Cosmos DB サービスのコレクション内のドキュメントに対して一意性制約を指定するための一意キー ポリシー構成を表します。

プロパティ

UniqueKeys

Azure Cosmos DB サービスの UniqueKey コレクション内のドキュメントの一意性を保証する コレクションを取得します。

適用対象