UniqueKeyPolicy クラス
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
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 コレクション内のドキュメントの一意性を保証する コレクションを取得します。 |
適用対象
Azure SDK for .NET