Skip to content

Instantly share code, notes, and snippets.

@gmantri
Created June 24, 2021 13:52
Show Gist options
  • Save gmantri/bcb61923628ed5fbfe9bfef0a68a5952 to your computer and use it in GitHub Desktop.
Save gmantri/bcb61923628ed5fbfe9bfef0a68a5952 to your computer and use it in GitHub Desktop.
using System;
using System.Threading.Tasks;
using Microsoft.Azure.Cosmos.Table;
namespace CosmosDbTableSamples
{
class Program
{
static async Task Main(string[] args)
{
string accountName = "account-name";
string accountKey =
"account-key";
string tableUrl = "https://account-name.table.core.windows.net";
string tableName = "Currency";
StorageCredentials credentials = new StorageCredentials(accountName, accountKey);
CloudTableClient tableClient = new CloudTableClient(new Uri(tableUrl), credentials);
CloudTable table = tableClient.GetTableReference(tableName);
string date = "2021-06-24";
string currency = "USD";
var retrieveOperation = TableOperation.Retrieve<CurrencyEntity>(currency, date);
var result = await table.ExecuteAsync(retrieveOperation);
var entity = result.Result as CurrencyEntity;
Console.WriteLine(entity.Close);//Prints proper value
}
}
public class CurrencyEntity : TableEntity
{
public CurrencyEntity() { }
public CurrencyEntity(string currency, string date)
{
Currency = currency.ToUpper();
Date = date;
PartitionKey = currency.ToUpper();
RowKey = date;
}
public CurrencyEntity(string currency, string date, string close)
{
Currency = currency.ToUpper();
Date = date;
Close = close;
PartitionKey = currency.ToUpper();
RowKey = date;
}
public string Currency { get; set; }
public string Date { get; set; }
public string Close { get; set; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment