3

Just what it says on the tin, I have a design problem where normally PredicateBuilder would be the obvious answer, but when executing, I get errors such as :

The expression 
((([10007].PartitionKey == "df2907ad-2094-4b7a-9796-d077f14b25bc") 
And True) 
And Invoke(f => (True AndAlso Invoke(job => (job.MigrationExecutionId == "5fa0bd4c-4745-4452-8e52-a0329c00dafb"), f)), [10007])) 
is not supported.

Any way to use Predicate builder, or some other form of expression tree syntax to build up a query and run it against Azure Table?

Jason Coyne
  • 6,509
  • 8
  • 40
  • 70

2 Answers2

1

Short answer: no. ATS offers only limited linq support.

Igorek
  • 15,716
  • 3
  • 54
  • 92
  • Do you have any links to documentation on that? – Tom Halladay Nov 10 '13 at 14:44
  • 1
    Here's everything that ATS supports: http://msdn.microsoft.com/en-us/library/windowsazure/dd135725.aspx – Igorek Nov 10 '13 at 21:51
  • 1
    Hey Igor, not even a hello?! I know that Azure has the limited syntax, but I was hoping that I could build up the query (within the bounds of that syntax) via an expression/predicate so that I could build the query more dynamically. – Jason Coyne Nov 11 '13 at 15:39
0

Yes, you can use PredicateBuilder with Azure Table Storage. Let's say you want to build a query of the format (pseudo code):

where partitionkey = "X" and (email = "Y" or email = "Z")

This can be done as follows

    public string[] GetByEmail(string companyId, string[] emails)
    {
        var inner = PredicateBuilder.New<IssuerTableEntity>(false);
        foreach (var email in emails.Select(x => x.ToLowerInvariant()).Distinct())
        {
            var temp = email;
            inner = inner.Or(x => x.EmailLowercase == temp);
        }

        var outer = PredicateBuilder.New<MyTableEntity>(false);
        outer = outer.And(x => x.PartitionKey == companyId);
        outer = outer.And(inner);

        CloudTable table = GetTable(MyTableName);  
        return table.CreateQuery<MyTableEntity>()
            .Where(outer)
            .Select(x => x.RowKey)
            .ToArray();
    }

Note the use of Distinct() - this was because I got errors when supplying duplicates.

Ian Kemp
  • 28,293
  • 19
  • 112
  • 138
Sean Kearon
  • 10,987
  • 13
  • 77
  • 93