Reputation: 6636
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?
Upvotes: 3
Views: 422
Reputation: 11427
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.
Upvotes: 0