AZURE

Inserting Null Value for Integer columns in Windows Azure Table

I recommend to read  below post before you start reading this post

Creating Azure Table using CloudTableClient.CreateTableIfNotExist

There may be requirement when you need to insert null values for values type columns in Azure table. In our recent project, we had a requirement to insert null values for integer columns. Usually if you don’t provide any value to Integer variable, it would get initialized as 0, since they are value type’s variables. This post will focus on providing null values for integer columns

Very first you need to define and entity as below,

image

 

You may have noticed that I am making integer properties as Nullable types

image

Now create Azure table as below,

image

Then you can insert null value for integer columns as below,

image

For your reference full source code to insert null values is as below,


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(
account.TableEndpoint.ToString(),
account.Credentials);
string tableName = "School";
tableClient.CreateTableIfNotExist(tableName);
TableServiceContext  context = tableClient.GetDataServiceContext();
SchoolEntity entity = new SchoolEntity
{
Age = null,
Name = "DJ",
PartitionKey = "S",
RollNumber  = null ,
RowKey = Guid.NewGuid().ToString()
};

context.AddObject(tableName, entity);
context.SaveChanges();

Console.WriteLine("Saved");
Console.ReadKey(true);


}
}

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

}

 

In this way you can insert null values. I hope this post was useful. Thanks for reading Smile

If you find my posts useful you may like to follow me on twitter http://twitter.com/debug_mode or may like Facebook page of my blog http://www.facebook.com/DebugMode.Net 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

About Dhananjay Kumar

Dhananjay Kumar is Developer, Blogger , Speaker, Learner , Mindcracker & Microsoft MVP.

Discussion

Trackbacks/Pingbacks

  1. Pingback: Windows Azure and Cloud Computing Posts for 10/12/2011+ - Windows Azure Blog - October 13, 2011

  2. Pingback: Monthly Report October 2011: Total Posts 31 « debug mode…… - November 1, 2011

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 1,380 other followers

Tweets

Categories

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my current or previous employer's view in anyway. © Copyright 2012