-
-
Save gmantri/bcb61923628ed5fbfe9bfef0a68a5952 to your computer and use it in GitHub Desktop.
This file contains 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
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