Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
public class AzureTableStorage<T> where T : TableEntity, IAzureStorageTable, new()
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
CloudTableClient tableClient;
CloudTable table;
public AzureTableStorage(string tableName)
tableClient = storageAccount.CreateCloudTableClient();
table = tableClient.GetTableReference(tableName);
public T Insert(T entity)
TableOperation insertOperation = TableOperation.Insert(entity);
return entity;
public List<T> GetAll(string partitionKey)
List<T> entities = new List<T>();
TableQuery<T> query = new TableQuery<T>().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, partitionKey));
entities = table.ExecuteQuery(query).ToList();
return entities;
public T Find(string partitionKey, string rowKey)
T entity = new T();
TableQuery<T> query = new TableQuery<T>().Where(
TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, partitionKey),
TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.Equal, rowKey)));
var tableSet = table.ExecuteQuery(query).ToList();
if (tableSet.Count >= 1)
return tableSet.First();
return null;
public interface IAzureStorageTable
void SetPartitionKey(string key);
void SetRowKey(string id);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment