Export (0) Print
Expand All

CloudTableClient.GetDataServiceContext Method

Updated: April 24, 2013

[This topic is part of the Windows Azure Storage Client Library 1.7, which has been deprecated. The current recommended version is Storage Client Library 3.0.]

Returns a TableServiceContext object for performing data operations against the Table service.

Namespace: Microsoft.WindowsAzure.StorageClient
Assembly: Microsoft.WindowsAzure.StorageClient (in Microsoft.WindowsAzure.StorageClient.dll)

'Usage

public TableServiceContext GetDataServiceContext ()

Return Value

Type: Microsoft.WindowsAzure.StorageClient.TableServiceContext

The runtime context to use for performing data operations against the Table service.

The following code example gets an entity from a table and deletes it.


public static void DeleteEntity(CloudStorageAccount storageAccount)
{
    // Create service client for credentialed access to the Table service.
    CloudTableClient tableClient = new CloudTableClient(storageAccount.TableEndpoint.ToString(),
        storageAccount.Credentials);
    // Get the context.
    TableServiceContext context = tableClient.GetDataServiceContext();
    // Get the first entity from the table.
    ProductEntity entity = context.CreateQuery<ProductEntity>("Products").AsTableServiceQuery<ProductEntity>().FirstOrDefault();
    // Delete the entity.
    context.DeleteObject(entity);
    // Save changes to the service.
    context.SaveChanges();
}
// Define a class that represents an entity.
class ProductEntity : TableServiceEntity
{
    public ProductEntity()
    {
    }
    public string ProductName { get; set; }
    public string Category { get; set; }
    public double Price { get; set; }
    public bool InStock { get; set; }
    public DateTime DateAdded { get; set; }
    public Int32 Quantity { get; set; }
}

The Windows Azure TableServiceContext object is derived from the DataServiceContext object provided by the WCF Data Services. This object provides a runtime context for performing data operations against the Table service, including querying entities and inserting, updating, and deleting entities.


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Development Platforms

Windows Vista, Windows 7 and Windows Server 2008

Target Platforms

Show:
© 2014 Microsoft