I'm writing a method that retrieves an entity from an Azure Table Storage service. I need to return the entity as type User rather than as TableResult. The following compiles, but always returns Null:
var partitionKey = "user";
var retrieveOperation = TableOperation.Retrieve<TableEntity>(partitionKey, userName);
var result = _table.Execute(retrieveOperation);
if (result == null)
{
return null;
}
return result.Result as User;
I'm assuming this is because the cast from TableResult to User doesn't work for some reason. Casting it like (User)result.Result actally throws an error at runtime. I've seen an example using Linq on a list of entities, but how do you cast a single result?