CAST supports Azure Cosmos DB via its NoSQL for .NET extension. Details about how this support is provided for .NET source code is discussed below.

Supported Client Libraries

(tick)
Azure Cosmos DB .NET SDK 3.x for SQL API (error)

Supported Operations

OperationMethods Supported
Create
  • Microsoft.Azure.Documents.Client.DocumentClient.CreateDocumentCollectionAsync
  • Microsoft.Azure.Documents.IDocumentClient.CreateDocumentCollectionAsync
  • Microsoft.Azure.Documents.Client.DocumentClient.CreateDocumentCollectionIfNotExistsAsync
  • Microsoft.Azure.Documents.IDocumentClient.CreateDocumentCollectionIfNotExistsAsync
Insert
  • Microsoft.Azure.Documents.Client.DocumentClient.CreateDocumentAsync


  • Microsoft.Azure.Documents.IDocumentClient.CreateDocumentAsync
  • Microsoft.Azure.Documents.Client.DocumentClient.UpsertDocumentAsync
  • Microsoft.Azure.Documents.IDocumentClient.UpsertDocumentAsync
Update
  • Microsoft.Azure.Documents.Client.DocumentClient.ReplaceDocumentAsync
  • Microsoft.Azure.Documents.IDocumentClient.ReplaceDocumentAsync
  • Microsoft.Azure.Documents.Client.DocumentClient.ReplaceDocumentCollectionAsync
  • Microsoft.Azure.Documents.IDocumentClient.ReplaceDocumentCollectionAsync
  • Microsoft.Azure.Documents.Client.DocumentClient.UpsertDocumentAsync
  • Microsoft.Azure.Documents.IDocumentClient.UpsertDocumentAsync
Select
  • Microsoft.Azure.Documents.Client.DocumentClient.ReadDocumentAsync
  • Microsoft.Azure.Documents.IDocumentClient.ReadDocumentAsync
  • Microsoft.Azure.Documents.Client.DocumentClient.ReadDocumentCollectionAsync
  • Microsoft.Azure.Documents.IDocumentClient.ReadDocumentCollectionAsync
  • Microsoft.Azure.Documents.Client.DocumentClient.CreateDocumentQuery
  • Microsoft.Azure.Documents.Client.DocumentClient.CreateDocumentQuery
Delete
  • Microsoft.Azure.Documents.Client.DocumentClient.DeleteDocumentAsync
  • Microsoft.Azure.Documents.IDocumentClient.DeleteDocumentAsync'
  • Microsoft.Azure.Documents.Client.DocumentClient.DeleteDocumentCollectionAsync
  • Microsoft.Azure.Documents.IDocumentClient.DeleteDocumentCollectionAsync

Objects

IconDescription

DotNet CosmosDB Database

DotNet CosmosDB Collection

 

DotNet CosmosDB Unknown Database 

 

DotNet CosmosDB Unknown Collection 

Links

Links are created for transaction and function point needs:

Link typeWhen is this created? Methods Supported
parentLink

Between Azure CosmosDB database object and Azure CosmosDB collection object


useLinkBetween the caller .NET Method objects and Azure CosmosDB collection object


  • CreateDocumentCollectionAsync
  • CreateDocumentCollectionIfNotExistsAsync

useInsertLink

  • CreateDocumentAsync
  • UpsertDocumentAsync
useUpdateLink
  • ReplaceDocumentAsync
  • ReplaceDocumentCollectionAsync
  • UpsertDocumentAsync
useSelectLink
  • ReadDocumentAsync
  • ReadDocumentCollectionAsync
  • CreateDocumentQuery
useDeletetLink
  • DeleteDocumentAsync
  • DeleteDocumentCollectionAsync

What results can you expect?

Once the analysis/snapshot generation has completed, you can view the results in the normal manner (for example via CAST Enlighten). Some examples are shown below.

Azure Cosmos DB Database and Table Creation


private static readonly string databaseName = "samples";
private static readonly string collectionName = "document-samples";

private static async Task Initialize()
        {
            await client.CreateDatabaseIfNotExistsAsync(new Database { Id = databaseName });

            // We create a partitioned collection here which needs a partition key. Partitioned collections
            // can be created with very high values of provisioned throughput (up to OfferThroughput = 250,000)
            // and used to store up to 250 GB of data. You can also skip specifying a partition key to create
            // single partition collections that store up to 10 GB of data.
            DocumentCollection collectionDefinition = new DocumentCollection();
            collectionDefinition.Id = collectionName;

            // For this demo, we create a collection to store SalesOrders. We set the partition key to the account
            // number so that we can retrieve all sales orders for an account efficiently from a single partition,
            // and perform transactions across multiple sales order for a single account number. 
            collectionDefinition.PartitionKey.Paths.Add("/AccountNumber");

            // Use the recommended indexing policy which supports range queries/sorting on strings
            collectionDefinition.IndexingPolicy = new IndexingPolicy(new RangeIndex(DataType.String) { Precision = -1 });

            // Create with a throughput of 1000 RU/s
            await client.CreateDocumentCollectionIfNotExistsAsync(
                UriFactory.CreateDatabaseUri(databaseName),
                collectionDefinition,
                new RequestOptions { OfferThroughput = 1000 });
        }

Insert Operation


private static async Task CreateDocumentsAsync()
        {
            Uri collectionUri = UriFactory.CreateDocumentCollectionUri(databaseName, collectionName);
            Console.WriteLine("\n1.1 - Creating documents");
            SalesOrder salesOrder = GetSalesOrderSample("SalesOrder1");
            await client.CreateDocumentAsync(collectionUri, salesOrder);
			SalesOrder2 newSalesOrder = GetSalesOrderV2Sample("SalesOrder2");
            await client.CreateDocumentAsync(collectionUri, newSalesOrder);
		}

Select Operation


private static async Task ReadDocumentAsync()
        {
            Console.WriteLine("\n1.2 - Reading Document by Id");

            var response = await client.ReadDocumentAsync(
            	UriFactory.CreateDocumentUri(databaseName, collectionName, "SalesOrder1"), 
                new RequestOptions { PartitionKey = new PartitionKey("Account1") });
		}

private static async Task ReadDocumentCollectionAsync()
        {
            Console.WriteLine("\n1.7 - Reading a document");
            ResourceResponse<Document> response = await client.ReadDocumentCollectionAsync(
                UriFactory.CreateDocumentUri(databaseName, collectionName, "SalesOrder3"),
                new RequestOptions { PartitionKey = new PartitionKey("Account1") });
        }

private static SalesOrder QueryDocuments()
        {
            Console.WriteLine("\n1.4 - Querying for a document using its AccountNumber property");

            SalesOrder querySalesOrder = client.CreateDocumentQuery<SalesOrder>(
                UriFactory.CreateDocumentCollectionUri(databaseName, collectionName))
                .Where(so => so.AccountNumber == "Account1")
                .AsEnumerable()
                .First();

            Console.WriteLine(querySalesOrder.AccountNumber);
            return querySalesOrder;
        }

Update Operation


	private static async Task ReplaceDocumentAsync(SalesOrder order)
        {
            Console.WriteLine("\n1.5 - Replacing a document using its Id");
            order.ShippedDate = DateTime.UtcNow;
            ResourceResponse<Document> response = await client.ReplaceDocumentAsync(
                UriFactory.CreateDocumentUri(databaseName, collectionName, order.Id), 
                order);

            var updated = response.Resource;
            Console.WriteLine("Request charge of replace operation: {0}", response.RequestCharge);
            Console.WriteLine("Shipped date of updated document: {0}", updated.GetPropertyValue<DateTime>("ShippedDate"));
        }

private static async Task ReplaceDocumentCollectionAsync()
        {
            Console.WriteLine("\n1.7 - Updating a document");
            ResourceResponse<Document> response = await client.ReplaceDocumentCollectionAsync(
                UriFactory.CreateDocumentUri(databaseName, collectionName, "SalesOrder3"),
                new RequestOptions { PartitionKey = new PartitionKey("Account1") });

            Console.WriteLine("Request charge of update operation: {0}", response.RequestCharge);
            Console.WriteLine("StatusCode of operation: {0}", response.StatusCode);
        }

Upsert Operation


private static async Task UpsertDocumentAsync()
        {
            Console.WriteLine("\n1.6 - Upserting a document");

            var upsertOrder = GetSalesOrderSample("SalesOrder3");
            ResourceResponse<Document> response = await client.UpsertDocumentAsync(UriFactory.CreateDocumentCollectionUri(databaseName, collectionName), upsertOrder);
            var upserted = response.Resource;

            Console.WriteLine("Request charge of upsert operation: {0}", response.RequestCharge);
            Console.WriteLine("StatusCode of this operation: {0}", response.StatusCode);
            Console.WriteLine("Id of upserted document: {0}", upserted.Id);
            Console.WriteLine("AccountNumber of upserted document: {0}", upserted.GetPropertyValue<string>("AccountNumber"));

            upserted.SetPropertyValue("AccountNumber", "updated account number");
            response = await client.UpsertDocumentAsync(UriFactory.CreateDocumentCollectionUri(databaseName, collectionName), upserted);
            upserted = response.Resource;

            Console.WriteLine("Request charge of upsert operation: {0}", response.RequestCharge);
            Console.WriteLine("StatusCode of this operation: {0}", response.StatusCode);
            Console.WriteLine("Id of upserted document: {0}", upserted.Id);
            Console.WriteLine("AccountNumber of upserted document: {0}", upserted.GetPropertyValue<string>("AccountNumber"));
        }


Delete Operation


 private static async Task DeleteDocumentAsync()
        {
            Console.WriteLine("\n1.7 - Deleting a document");
            ResourceResponse<Document> response = await client.DeleteDocumentAsync(
                UriFactory.CreateDocumentUri(databaseName, collectionName, "SalesOrder3"),
                new RequestOptions { PartitionKey = new PartitionKey("Account1") });

            Console.WriteLine("Request charge of delete operation: {0}", response.RequestCharge);
            Console.WriteLine("StatusCode of operation: {0}", response.StatusCode);
        }

private static async Task DeleteDocumentCollectionAsync()
        {
            Console.WriteLine("\n1.7 - Deleting a document");
            ResourceResponse<Document> response = await client.DeleteDocumentCollectionAsync(
                UriFactory.CreateDocumentUri(databaseName, collectionName, "SalesOrder3"),
                new RequestOptions { PartitionKey = new PartitionKey("Account1") });

            Console.WriteLine("Request charge of delete operation: {0}", response.RequestCharge);
            Console.WriteLine("StatusCode of operation: {0}", response.StatusCode);
        }



Evolution

Limitations

Future Development