Skip to content

Instantly share code, notes, and snippets.

@plaurin
Last active December 14, 2015 21:08
Show Gist options
  • Save plaurin/5148570 to your computer and use it in GitHub Desktop.
Save plaurin/5148570 to your computer and use it in GitHub Desktop.
var connectionString="...";
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);
var client = storageAccount.CreateCloudTableClient();
var table = client.GetTableReference("Demo");
table.CreateIfNotExists();
// dynamic keyword to use a dynamic entity
dynamic entity = new ElasticTableEntity();
entity.PartitionKey = "Partition123";
entity.RowKey = (DateTime.MaxValue.Ticks - DateTime.Now.Ticks).ToString();
entity.Name = "Pascal";
entity.Number = 34;
entity.Bool = false;
entity.Date = new DateTime(1912, 3, 4);
entity.TokenId = Guid.NewGuid();
entity["LastName"] = "Laurin";
// Insert the entity we created dynamically
table.Execute(TableOperation.Insert(entity));
// Query all entities in the table
var query = new TableQuery<ElasticTableEntity>();
var result = table.ExecuteQuery(query)
.ToList().Dump("Result");
// Query only a subset of properties
var result2 = table.ExecuteQuery(query.Select(new[] { "FirstName", "Date" }))
.ToList().Dump("Result with projection");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment