Since I started dealing with Azure tables I’ve become frustrated that there is no ad-hoc query tool, nothing equivalent to SQL Server Management Studio. Then I heard about LINQPad and figured there must be a way to use it to query Azure tables using LINQ and indeed there is as I’ll explain here (this post assumes that you have a working knowledge of LINQPad and Azure storage).
Firstly you need to reference the correct assemblies. I’ve been using the StorageClient that is provided with the Azure Samples in the Azure SDK (March 2009 CTP of the SDK linked here) which in turn uses ADO.Net Services client library hence you’ll need to reference the following assemblies:
- StorageClient.dll
- System.Data.Services.Client.dll
You’ll also need to reference your DataServiceContext implementation. For demo purposes I am pulling data from my Tweetpoll application so I’m referencing the assembly containing my TweetPollDataServiceContext class - TweetPoll.dll:
We also need to import the namespaces into LINQPad. You’ll need the following:
- Microsoft.Samples.ServiceHosting.StorageClient
- System.Data.Services.Client
plus whichever namespace holds your DataServiceContext implementation:
Thereafter you just need to write some code. You need to supply the following:
- Your Azure storage account name
- Your Azure storage shared key
- The name of your DataServiceContext implementation
- A LINQ query
Here’s my code:
var accountName = "jamiekt"; // 1) Enter your storage account name
var sharedKey = "smXblLn+UgXR6ysbIhoeTfE3dyOZhAaONXOP/SUawRSLzCWwDXrhkpRG45A5aeAP5IEjSBEN2mEmPM8O5HnWGQ=="; // 2) SharedKey
var uri = new System.Uri("http://table.core.windows.net/");
var tableAccountInfo = new StorageAccountInfo(uri, null, accountName, sharedKey);
var svc = new TweetPollDataServiceContext(tableAccountInfo); // 3) Specify your DataServiceContext
// 4) Supply your query
var query = from row in svc.Table
select row;
query.Dump();
And here are the results in LINQPad:
Hope that helps!!!
@Jamiet