tags:

views:

100

answers:

2

Hi all I'm just tinkering with F# and Azure and have come unstuck with the TableServiceContext. I was converting this post into an F# implementation which was going well until it gets to the point where you actually query the data. In C# the code is

public IEnumerable<ContactDataModel> Select()
{
    var results = from c in _ServiceContext.ContactTable
                  select c;

    var query = results.AsTableServiceQuery<ContactDataModel>();
    var queryResults = query.Execute();

    return queryResults;
}

where results is an IQueryable and AsTableServiceQuery looks like it's an extension method.

Does anyone know how to perform these types of queries against Azure storage using the TableServiceContext?

I'd have thought something like

seq { for c in _ServiceContext.ContactTable do yield c }

or even with the powerpack

query <@ seq { for c in _ServiceContext.ContactTable do yield c } @>

would be a good starting point but I've no idea where to go from here. I suppose the worst case scenario is to leave this as C# code and then call it from F# but would like to know of any alternatives.

Cheers Dylan

A: 

Based on

http://blogs.msdn.com/b/dsyme/archive/2009/10/23/a-quick-refresh-on-query-support-in-the-f-power-pack.aspx

I think you're on the right track. You might have to call the extension method 'explicitly' (e.g. as a static method that takes the receiver as a parameter), but I think it would work - have you tried that?

Brian
+1  A: 

Use query <@ seq { ... } @> and cast the result to IQueryable (it is an unfortunate limitation of query support in PowerPack). The rest should be the same as C#:

let results = 
  query <@ seq { for c in _ServiceContext.ContactTable do yield c } @> 
    :?> IQueryable<DataContactModel>
let query = results.AsTableServiceQuery()
query.Execute()

(I have not tried it)

Mitya
worked like a charm thanks. To anyone else looking at this later you need to add the statement open System.Linq to get at the IQueryable<> type
Dylan