How you can store decimal data in Windows Azure Table Storage?

At this point Windows Azure Table Storage does not support natively storing decimal point data as described in the below supported property types which is a subset of data types defined by the ADO.NET Data Services specification:

 

ADO.NET Data Services type

Common Language Runtime type

Details

Edm.Binary

byte[]

An array of bytes up to 64 KB in size.

Edm.Boolean

bool

A Boolean value.

Edm.DateTime

DateTime

A 64-bit value expressed as Coordinated Universal Time (UTC). The supported DateTime range begins from 12:00 midnight, January 1, 1601 A.D. (C.E.), UTC. The range ends at December 31, 9999.

Edm.Double

double

A 64-bit floating point value.

Edm.Guid

Guid

A 128-bit globally unique identifier.

Edm.Int32

Int32 or int

A 32-bit integer.

Edm.Int64

Int64 or long

A 64-bit integer.

Edm.String

String

A UTF-16-encoded value. String values may be up to 64 KB in size. (Default Value)

 

While you can store your decimal data as string in the table and in your code you can use client library based serializer which supports decimal. So you can in effect use decimal by just changing the data type to PrimitiveTypeKind.String in your ReadingWritingEntityEvent handler.

 

Using custom attribute the solution becomes fairly convenient. For example, the entity classes just use the following code to get decimal data:

        [EntityDataType(PrimitiveTypeKind.String)]

        public decimal Quantity { get; set; }

 

The above code just works fine with string type data but doesn’t work for other unsupported types like enums or TimeSpan.

Thanks to Windows Azure Product team for providing this information.