Last active
December 14, 2015 21:08
-
-
Save plaurin/5148570 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
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