Creating Azure Table using CloudTableClient.CreateTableIfNotExist

I discussed Three simple steps to create Azure table in my last post. Just after submitting the post, I got a comment from Neil Mackenzie that I can avoid creation of context class [Step 2] in last post. He helped me with the link for the best practice on MSDN

This post is to accommodate suggestion given by him and recommendation given on MSDN.

In this post we will see how to create Azure table using CloudTableClient.CreatTableIfNotExist method.

Add References

If you are creating table from a console application then you need to add below references to your project,



And Microsoft.WindowsAzure.Serviceruntime.dll


Create Entity class

To represent entity class, we need to create a class inheriting from class TableServiceEntity. SchoolEntity class will be as below,


If you notice in above code snippet there is no

  1. Row Key
  2. Partition Key
  3. Calling base class constructor [ As I discussed here ]

Now when you make object of SchoolEntity class, in intellisense you will get RowKey,PartitionKey and TimeStamp to set as below,



Creating Account object


Pass connection string as of your storage account.

Creating Table Client


Creating Table


Creating Table Context


Creating Object to Insert


Adding Object to table


Putting all the code together,

using System;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.StorageClient;

namespace ConsoleApplication7
class Program
static void Main(string[] args)
CloudStorageAccount account = CloudStorageAccount.Parse("connectionString");
CloudTableClient tableClient = new CloudTableClient(
string tableName = "School";

TableServiceContext  context = tableClient.GetDataServiceContext();

SchoolEntity entity = new SchoolEntity
Age = 9,
Name = "DJ",
PartitionKey = "S",
RollNumber  = null ,
RowKey = Guid.NewGuid().ToString()
context.AddObject(tableName, entity);



public class SchoolEntity : TableServiceEntity
public string Name { get; set; }
public int ? RollNumber { get; set; }
public int Age { get; set; }


In this way you can create a table. I hope this post was useful. Thanks for reading Smile

If you find my posts useful you may like to follow me on twitter or may like Facebook page of my blog If you want to see post on a particular topic please do write on FB page or tweet me about that, I would love to help you

4 responses to “Creating Azure Table using CloudTableClient.CreateTableIfNotExist”

  1. […] Creating Azure Table using CloudTableClient.CreateTableIfNotExist […]

  2. […] Dhananjay Kumar (@debug_mode) explained Inserting Null Value for Integer columns in Windows Azure Table in a 10/12/2011 post: I recommend to read below post before you start reading this post: Creating Azure Table using CloudTableClient.CreateTableIfNotExist. […]

  3. […] Creating Azure Table using CloudTableClient.CreateTableIfNotExist […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create a website or blog at