Table of Contents

Class TableEntityAdapter<T>

Namespace
Microsoft.WindowsAzure.Storage.Table
Assembly
Microsoft.WindowsAzure.Storage.dll

Adapter class to allow reading and writing objects to Azure Table Storage without inheriting from TableEntity class or implementing ITableEntity interface. The objects can be simple POCO objects or complex objects with nested complex properties.

public class TableEntityAdapter<T> : TableEntity, ITableEntity

Type Parameters

T

The type of object to read and write to Azure Table Storage, it can be a class or a struct.

Inheritance
TableEntityAdapter<T>
Implements
Inherited Members

Constructors

TableEntityAdapter()

Initializes a new instance of the TableEntityAdapter<T> class.

public TableEntityAdapter()

TableEntityAdapter(T)

Initializes a new instance of the TableEntityAdapter<T> class with the specified object.

public TableEntityAdapter(T originalEntity)

Parameters

originalEntity T

The object to write to Azure Table Storage.

TableEntityAdapter(T, string, string)

Initializes a new instance of the TableEntityAdapter<T> class with the specified object, partition key and row key.

public TableEntityAdapter(T originalEntity, string partitionKey, string rowKey)

Parameters

originalEntity T

The object to write to Azure Table Storage.

partitionKey string

A string containing the partition key value for the entity.

rowKey string

A string containing the row key value for the entity.

Properties

OriginalEntity

The original entity that is read and written to azure table storage.

public T OriginalEntity { get; set; }

Property Value

T

Methods

ReadEntity(IDictionary<string, EntityProperty>, OperationContext)

Deserializes TableEntityAdapter<T> instance using the specified IDictionary<TKey, TValue> that maps property names of the OriginalEntity to typed EntityProperty values and stores it in the OriginalEntity property.

public override void ReadEntity(IDictionary<string, EntityProperty> properties, OperationContext operationContext)

Parameters

properties IDictionary<string, EntityProperty>

An IDictionary<TKey, TValue> object that maps property names to typed EntityProperty values.

operationContext OperationContext

An OperationContext object that represents the context for the current operation.

WriteEntity(OperationContext)

Serializes the IDictionary<TKey, TValue> of property names mapped to EntityProperty data values from the OriginalEntity property.

public override IDictionary<string, EntityProperty> WriteEntity(OperationContext operationContext)

Parameters

operationContext OperationContext

An OperationContext object that represents the context for the current operation.

Returns

IDictionary<string, EntityProperty>

An IDictionary<TKey, TValue> object that maps string property names to EntityProperty typed values created by serializing this table entity instance.

Remarks

If OriginalEntity is a simple POCO object with simple properties (primitive types, string, byte[], ...), WriteEntity(OperationContext) method will create EntityProperty objects using these properties.
Ie. A simple POCO object A with properties of B and C with this structure A->B, A->C, will be converted to key value pairs of {"B", EntityProperty(B)}, {"C", EntityProperty(C)}.
If OriginalEntity has complex properties (and potentially these properties having complex properties of their own), WriteEntity(OperationContext) method will flatten OriginalEntity first.
Ie. An object A with a simple property of B and complex properties of C and D which have their own properties of E and F with this structure A->B, A->C->E and A->D->F, will be flattened to key value pairs of:
{"B", EntityProperty(B)}, {"C_E", EntityProperty(E)} and {"D_F", EntityProperty(F)}.
For each key value pair:
1. The key is composed by appending the names of the properties visited from root (A) to end node property (E or F) delimited by "_".
2. The value is the EntityProperty object, instantiated by the value of the end node property.
All key value pairs will be stored in the returned IDictionary<TKey, TValue>.
ReadEntity(IDictionary<string, EntityProperty>, OperationContext) method recomposes the original object (POCO or complex) using the IDictionary<TKey, TValue> returned by this method and store it in OriginalEntity property.
Properties that are marked with IgnorePropertyAttribute in the OriginalEntity object will be ignored and not processed by this method.