DataServiceContext.CreateQuery<T> Method
Creates a data service query for data of a specified generic type.
Assembly: System.Data.Services.Client (in System.Data.Services.Client.dll)
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.
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.
- 3/9/2012
- sarbanjeet
$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")
- 12/9/2011
- IvanBrug