CloudTableClient.GetDataServiceContext Method

Storage Client Library NET API

[This topic is part of the Microsoft Azure Storage Client Library 1.7, which has been deprecated. See Storage Client Library for the latest version.]

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

Visual Basic
Dim instance As CloudTableClient
Dim returnValue As TableServiceContext

returnValue = instance.GetDataServiceContext

Syntax

Visual Basic
Public Function GetDataServiceContext As TableServiceContext
C#
public TableServiceContext GetDataServiceContext ()
C++
public:
TableServiceContext^ GetDataServiceContext ()
J#
JScript

Return Value

Type: Microsoft.WindowsAzure.StorageClient.TableServiceContext

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

Example

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

C# Copy Code
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; }
}

Remarks

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.


Thread Safety

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

Platforms

Development Platforms

Windows Vista, Windows 7, Windows Server 2008, Windows 8.1, Windows Server 2012 R2, Windows 8 and Windows Server 2012

Change History

See Also