Skip to content

Table queries: Add a simple way to read from Azure Table Storage #5

@dmohl

Description

@dmohl

From Tuomas:

The main thing is that the user would like to do table-service-query and not fetch the whole table. But the supported operations are very limited: http://msdn.microsoft.com/en-us/library/windowsazure/dd135725.aspx
I currently use this kind of (non-Fog-)code (of course it would be better to search only by rowkey to not get full table scan, but it is not always possible):

open System
open System.Data
open System.Linq
open Fog.Storage.Table
open System.Configuration
open System.Data.Services.Common
open Microsoft.WindowsAzure.StorageClient

let getItemByCondition partitionKey searchCondition =
let context = BuildTableClient().GetDataServiceContext()
let query =
let beginQuery = query { for item in context.CreateQuery(Azure user table) do
where (item.PartitionKey = partitionKey) }
let filterQuery:IQueryable = searchCondition(beginQuery);
let selectQuery = query { for item in filterQuery do
take 1
select item}
selectQuery
query.AsTableServiceQuery().Execute()
|> Seq.tryFind(fun _ -> true)

let myItem =
let searched = "something"
getItemByCondition "myPartition" (fun iq -> iq.Where(fun (i:MyDataType) -> i.Something = searched))

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions