Skip to content

Instantly share code, notes, and snippets.

@EricAtMSFT
Created March 15, 2016 06:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EricAtMSFT/d9d46317b43b24177a77 to your computer and use it in GitHub Desktop.
Save EricAtMSFT/d9d46317b43b24177a77 to your computer and use it in GitHub Desktop.
/// <summary>
/// Checks if the defined document database and collection exists
/// and initializes them if they don't.
/// </summary>
public async Task InitializeDatabaseIfNotExisting(string serverPath)
{
var database = _documentClient.CreateDatabaseQuery()
.Where(db => db.Id == _documentDataBaseId)
.AsEnumerable()
.FirstOrDefault();
if (database == null)
{
database = await CreateDocumentDbDatabase();
}
var documentCollection = _documentClient.CreateDocumentCollectionQuery(database.SelfLink)
.Where(c => c.Id == _documentCollectionId)
.AsEnumerable()
.FirstOrDefault();
if (documentCollection == null)
{
await CreateDocumentDbCollection(database);
}
await InitializeStoredProceduresIfNotExisting(serverPath);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment