0 out of 5 rated this helpful - Rate this topic

DataServiceContext.CreateQuery<T> Method

Creates a data service query for data of a specified generic type.

Namespace:  System.Data.Services.Client
Assembly:  System.Data.Services.Client (in System.Data.Services.Client.dll)
public DataServiceQuery<T> CreateQuery<T>(
	string entitySetName
)

Type Parameters

T

The type returned by the query

Parameters

entitySetName
Type: System.String
A string that resolves to a URI.

Return Value

Type: System.Data.Services.Client.DataServiceQuery<T>
A new DataServiceQuery<TElement> instance that represents a data service query.

.NET Framework

Supported in: 4, 3.5 SP1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Example (c#)
$0$0 $0$0 $0$0 $0$0 $0$0 $0 public bool GetEntity<T>(string tableName, string partitionKey, out T entity) where T : TableServiceEntity$0 $0        {$0 $0            entity = null;$0 $0$0 $0 $0           $0 $0                 public CloudTableClient TableClient;$0 $0$0 $0 $0                TableServiceContext tableServiceContext = TableClient.GetDataServiceContext();$0 $0                IQueryable<T> entities = (from e in tableServiceContext.CreateQuery<T>(tableName)$0 $0                                          where e.PartitionKey == partitionKey $0 $0                                          select e);$0 $0$0 $0 $0                entity = entities.FirstOrDefault();$0 $0$0 $0 $0                return true;$0 $0            } $0$0 $0$0 $0
.

.

Powershell example to read any TableServiceEntity as XElement

$assembly = [Reflection.Assembly]::LoadFile("Microsoft.WindowsAzure.StorageClient.dll")

$blobCreds = New-Object Microsoft.WindowsAzure.StorageCredentialsAccountAndKey("---storage-account---","---storage-key---")
$account = New-Object Microsoft.WindowsAzure.CloudStorageAccount($blobCreds,$false)$tableclient = [Microsoft.WindowsAzure.StorageClient.CloudStorageAccountStorageClientExtensions]::CreateCloudTableClient($account)

$dataServiceContext = $tableclient.GetDataServiceContext()

#
# create a type on the fly to bing the 3 well-known required properties
# PartitionKey, RowKey, DateTime
# Also, save the full XML of the entity in a different property
#
add-type -ReferencedAssemblies @("System.Xml","System.Xml.Linq") @"
public partial class TElement {   private string _PartitionKey;
   private string _RowKey;
   private System.DateTime _Timestamp;
   public string PartitionKey { get { return _PartitionKey; } set { _PartitionKey = value; } }
   public string RowKey { get { return _RowKey; } set { _RowKey = value; } }
   public System.DateTime Timestamp { get { return _Timestamp; } set { _Timestamp = value; } }   private System.Xml.Linq.XElement _XElement;
   public System.Xml.Linq.XElement XElement { get { return _XElement; } set { _XElement = value; } }
}
"@

#
# Create and set an event handler.
# this event-handler is invoked before deserialization.
# the event-handler saves the original XML as a property of the TElement instance
#
$readHandler = [System.EventHandler[System.Data.Services.Client.ReadingWritingEntityEventArgs]] {   
    param([System.Object]$sender, [System.Data.Services.Client.ReadingWritingEntityEventArgs]$eventArgs);    [TElement]$entity = [TElement]$eventArgs.Entity;
    $entity.XElement  = $eventArgs.Data;
}
$dataServiceContext.add_ReadingEntity($readHandler)

#
# generate a closed method from a generic method.
# the usual examples use a class derived from Microsoft.WindowsAzure.StorageClient.TableServiceEntity.
# System.Xml.Linq does a reflection-based binding, and does not care as long as we provide
# a type with 3 required settable properties
#
$method = [Microsoft.WindowsAzure.StorageClient.TableServiceContext].GetMethod("CreateQuery")
$closedMethod = $method.MakeGenericMethod([TElement])

#
# invoke the selection method on the table named `WADPerformanceCountersTable` and hold onto the collection
# the collection is lazy-enumerated anyway
#
$collection = $closedMethod.Invoke($dataServiceContext,"WADPerformanceCountersTable")