Start from the Azure portal at portal.azure.com and first of all, create a new Cosmos DB account. The following screenshot is German, however you’ll likely find your way: Note that there are several APIs you can use for Cosmos DB. Let’s choose “SQL” as I fully trust we’d be able to connect to MongoDB or Cassandra using the corresponding data providers. This takes a while and leaves me with enough time to change the language to English <g>: Once the process is finished it’s time to add a collection: Handily, Microsoft offers the download of an automatically generated .NET sample application once the collection has been created. The solution is called “To-Do” and – at the heart of it – has a model for the items contained in the collection:
public class Item { [JsonProperty(PropertyName = "id")] public string Id { get; set; } [JsonProperty(PropertyName = "name")] public string Name { get; set; } [JsonProperty(PropertyName = "description")] public string Description { get; set; } [JsonProperty(PropertyName = "isComplete")] public bool Completed { get; set; } }
private const string endpointUrl = "…"; private const string primaryKey = “…”; private DocumentClient client; private void button_Click(object sender, RoutedEventArgs e) { client = new DocumentClient(new Uri(endpointUrl), primaryKey); IQueryable<Item> itemQuery = this.client.CreateDocumentQuery<Item>( UriFactory.CreateDocumentCollectionUri("ToDoList", "Items"), "SELECT * FROM Items"); }
using (ListLabel LL = new ListLabel()) { LL.DataSource = itemQuery; LL.Design(); }
Jochen Bartlau leads the development at combit as Managing Director. He's a Microsoft .NET enthusiast driving innovation & agile project management. The mobile devices geek who used to be a physicist in his first life loves to spend his spare time with his family.