Guest User

Untitled

a guest
Nov 24th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. using (client = new DocumentClient(new Uri(endpointUrl), authorizationKey, connectionPolicy))
  2. {
  3. //this is where the magic is happening.
  4. //define a collection of UniqueKeys, which are in themselves a collection of Paths.
  5. var uniqueKeyPolicy = new UniqueKeyPolicy {UniqueKeys = new Collection<UniqueKey>{ new UniqueKey { Paths = new Collection<string> { "/name" } } }};
  6.  
  7. var db = await client.CreateDatabaseIfNotExistsAsync(new Database { Id = DatabaseName });
  8. var coll = await client.CreateDocumentCollectionIfNotExistsAsync(
  9. UriFactory.CreateDatabaseUri(DatabaseName),
  10. new DocumentCollection { Id = CollectionName, UniqueKeyPolicy = uniqueKeyPolicy }
  11. );
  12. Console.WriteLine("\n1.1. Created Collection \n{0}", coll);
  13.  
  14.  
  15. var doc1 = await client.CreateDocumentAsync(
  16. UriFactory.CreateDocumentCollectionUri(DatabaseName, CollectionName), new { name = "Ryan" }
  17. );
  18.  
  19. Console.WriteLine("\n1.1. Doc1 Created\n{0}", doc1);
  20.  
  21.  
  22. var doc2 = await client.CreateDocumentAsync(
  23. UriFactory.CreateDocumentCollectionUri(DatabaseName, CollectionName), new { name = "Ryan" }
  24. );
  25.  
  26. Console.WriteLine("\n1.1. Doc2 Created\n{0}", doc2);
  27. }
Add Comment
Please, Sign In to add comment