Introduction
In this article, I’m going to describe how to execute CRUD Operations in Azure Table Storage. CRUD stands for Create, Read, Update and Delete.
I'll show you the entire CRUD operation using ASP.NET MVC application, step-by-step.
Overview
Azure Table is structured column storage on NoSQL Cloud Database. It is not a relational database. Azure Table Storage can store just a table without any foreign keys or any other kind of relation. These tables are highly scalable and ideal for handling a large amount of data. Tables can be stored and queried for a large amount of data. The relational database can be stored using SQL Data Services, which is a separate service.
You can get more overview of Azure Table Storage from here.
To create this project, I’m using,
- .NET Framework 4.6
- Windows Azure Storage 8.1.1 package
- Visual Studio 2015
- MVC 5.0
Consideration
To create this CRUD operation, the following skills should be considered.
- Good knowledge of ASP.NET MVC 5
- OOPs concepts in C#
- Basic knowledge of NoSQL
Scope of Work (SOW)
I'm creating a Student database with CRUD operations
- Insert and Edit Screen - Here, I used a HTML form. At the time of edit, I'll fill it with Student data.

- Get and Delete Screen - Here, I use an HTML table. There are three buttons here - Edit, Change Status, and Delete.

Step 1
Create Azure Storage Account. Go to https://portal.azure.com and create Azure Storage Account.

Access Key & Connection String
After creating Azure Storage Account, go to that account and copy the access key and connection string of that account. It will be used in our MVC application.

Step 2
Create a new empty MVC application. Create a new project by going to File -> New -> Project…
Go to NuGet Package Manager console window and install -> “Install-Package WindowsAzure.Storage -Version 8.1.1”.
Step 3
Add “TableManager” class for accessing the Azure Table. And, use two namespaces.
- WindowsAzure.Storage;
- WindowsAzure.Storage.Table;
Remove the default Constructor from “TableManager” class. And, add a parameterized Constructor with the string parameter.
This constructor will create the table if it's not there in Storage. We put the Azure Storage Connection String in this constructor, which was declared above.
- public class TableManager
- {
- // private property
- private CloudTable table;
- // Constructor
- public TableManager(string _CloudTableName)
- {
- if (string.IsNullOrEmpty(_CloudTableName))
- {
- throw new ArgumentNullException("Table", "Table Name can't be empty");
- }
- try
- {
- string ConnectionString = "Your Azure Storage Connection String goes here";
- CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConnectionString);
- CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
- table = tableClient.GetTableReference(_CloudTableName);
- table.CreateIfNotExists();
- }
- catch (StorageException StorageExceptionObj)
- {
- throw StorageExceptionObj;
- }
- catch (Exception ExceptionObj)
- {
- throw ExceptionObj;
- }
- }
- }
Step 4
Add a generic method for Insert or Merge/Replace into "TableManager" class, where the generic value should be an inherited object of "TableEntity". I use Repository Pattern here.
Why do I use Generic Method?
Azure Table is Column-based NoSQL. Here, we can store any kind of Data and any Object. This is a flavor of NoSQL. We don’t know, which type of object we are going to insert. If we use a generic method, we can access any object.
- public void InsertEntity<T>(T entity, bool forInsert = true) where T : TableEntity, new()
- {
- try
- {
- if (forInsert)
- {
- var insertOperation = TableOperation.Insert(entity);
- table.Execute(insertOperation);
- }
- else
- {
- var insertOrMergeOperation = TableOperation.InsertOrReplace(entity);
- table.Execute(insertOrMergeOperation);
- }
- }
- catch (Exception ExceptionObj)
- {
- throw ExceptionObj;
- }
- }
Step 5
Similarly, add another generic method to Retrieve entity into "TableManager" class. In this method, you can pass the query. According to query, it will return the dataset.
Now, the question is, what kind of query can we pass here. Here is the demonstration of how to use the operator in Azure Table Storage.
| Operator | expression |
| Equal | eq |
| GreaterThan | gt |
| GreaterThanOrEqual | ge |
| LessThan | lt |
| LessThanOrEqual | le |
| NotEqual | ne |
| And | and |
| Not | not |
| Or | or |
Example
I’m using Student Object here. I want to get the Student data where the name of the student is equal to Albert Einstein.
The query looks like - Name eq ‘Albert Einstein’
- public List<T> RetrieveEntity<T>(string Query = null) where T : TableEntity, new()
- {
- try
- {
- // Create the Table Query Object for Azure Table Storage
- TableQuery<T> DataTableQuery = new TableQuery<T>();
- if (!String.IsNullOrEmpty(Query))
- {
- DataTableQuery = new TableQuery<T>().Where(Query);
- }
- IEnumerable<T> IDataList = table.ExecuteQuery(DataTableQuery);
- List<T> DataList = new List<T>();
- foreach (var singleData in IDataList)
- DataList.Add(singleData);
- return DataList;
- }
- catch (Exception ExceptionObj)
- {
- throw ExceptionObj;
- }
- }


John MarnoPosted Dec 3, 2019, 11:41 AM
I wish to echo Simone's comment. In RetrieveEntity the ExecuteQuery method is not supported by the CloudTable type, and the suggestion to change it to ExecuteQuerySegmented requires more parameters....while we are investigating, could you please look in to this issue and post an update? Thanks in advance!
SimonePosted Nov 24, 2019, 8:56 AM
I'm working in ASP.NET Core 2.2 project and I want to import this class library. First of all I have changed all Execute with ExecuteAsync, The problem is that IEnumerable<T> IDataList = table.ExecuteQuery(DataTableQuery); seems not supported.
Vishal BhandarePosted Feb 7, 2019, 3:20 AM
This is great article, simple and to the point. Can you please update with 'InsertOrReplace' method details.
Rafnas T PPosted Apr 11, 2018, 2:20 AM
Nice article, thank you for sharing and keep sharing..
Debasish SahooPosted Apr 11, 2018, 1:32 AM
Can we manage transaction in azure table storage