This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CosmosClient cosmosClient = new CosmosClientBuilder("https://localhost:8081", "key") | |
| .WithConnectionModeDirect() | |
| .WithApplicationName("CosmosStarter") | |
| .Build(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static class CosmosDbConnection | |
| { | |
| private const string EndpointUri = "https://localhost:8081"; | |
| private const string PrimaryKey = "yourprimarykey=="; | |
| private static CosmosClient _instance = null; | |
| private static readonly CosmosClientOptions CosmosClientOptions = new CosmosClientOptions() | |
| { | |
| ConnectionMode = ConnectionMode.Direct, | |
| ApplicationName = "CosmosStarter" | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "id": "CU7-36-8183", | |
| "CustomerId": "CU7-36-8183", | |
| "ModifiedDate": "2020-08-10T16:31:18.6928886+10:00", | |
| "Title": "Mr.", | |
| "FirstName": "Delfina", | |
| "LastName": "Rutherford", | |
| "MiddleName": "Skylar", | |
| "Suffix": "II", | |
| "CompanyName": "Cormier, Oberbrunner and Kunde", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public async Task<List<Order>> GetOrders(string customerId) | |
| { | |
| try | |
| { | |
| var sqlQueryText = "SELECT * FROM c WHERE c.CustomerId = @customerid"; | |
| Console.WriteLine("Running query: {0}\n", sqlQueryText); | |
| QueryDefinition queryDefinition = new QueryDefinition(sqlQueryText).WithParameter("@customerid", "CU7-36-8183" ); | |
| FeedIterator<Order> queryResultSetIterator = this._container.GetItemQueryIterator<Order>(queryDefinition); | |
| List<Order> orders = new List<Order>(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public async Task<Customer> GetCustomer(string customerId) | |
| { | |
| try | |
| { | |
| var customerResponse = await this._container.ReadItemAsync<Customer>(customerId, new PartitionKey(customerId)); | |
| return customerResponse; | |
| } | |
| catch (CosmosException ex) | |
| { | |
| Console.WriteLine("Exception occured in GetCustomer: {0} Message body is {1}.\n", ex.Message,ex.ResponseBody); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public async Task AddCustomer(Customer customer) | |
| { | |
| try | |
| { | |
| ItemResponse<Customer> customerResponse = await this._container.CreateItemAsync<Customer>(customer, new PartitionKey(customer.CustomerId)); | |
| } | |
| catch (CosmosException ex) | |
| { | |
| Console.WriteLine("Exception occured in AddCustomer: Message body is {0}.\n", ex.Message); | |
| throw; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public async Task CreateContainerAsync() | |
| { | |
| ContainerProperties containerProperties = new ContainerProperties() | |
| { | |
| Id = Guid.NewGuid().ToString(), | |
| PartitionKeyPath = "/CustomerId", | |
| IndexingPolicy = new IndexingPolicy() | |
| { | |
| Automatic = false, | |
| IndexingMode = IndexingMode.Lazy, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private readonly CosmosClient _cosmosClient; | |
| private CosmosDatabase _database; | |
| private CosmosContainer _container; | |
| private readonly string _databaseId = "thetaDb"; | |
| private readonly string _containerId = "CustomerContainer"; | |
| public CosmosDriver() | |
| { | |
| _cosmosClient = CosmosDbConnection.Instance; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| az cosmosdb sql database create \ | |
| --account-name eCommerceDb-AC \ | |
| --name "Customers" \ | |
| --resource-group eCommerceDb-RG |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| az cosmosdb create \ | |
| --name eCommerceDb-AC \ | |
| --kind GlobalDocumentDB \ | |
| --resource-group eCommerceDb-RG |