dtretyakov / WindowsAzure

.NET library aimed at managing and querying entities from Windows Azure Storage. It can be used as LINQ to Azure Tables.
MIT License
64 stars 27 forks source link

Bad request with Linq Query #35

Closed Daxez closed 8 years ago

Daxez commented 10 years ago

Using the TableSet class with a predefined Entity I ran a Linq query, which resulted in a bad request. When I viewed the request/response in Fiddler I ran into strange behavior:

The Linq Query was:

(from item in _table
 where item.CreateDate > mindate && item.ProcessName == processName 
&& (item.CreateDay == currentPartition || item.CreateDay == nextPartition || item.CreateDay == prevPartition)
select item)

Where CreateDate is a DateTime? and mindate is a valid DateTime. CreateDay and current/prev/nextPartition are both strings as well as processName. _table is the TableSet in this case. The Entity is strongly typed and the columns are all available in storage.

The request sent by the application was (URL decoded):

$filter=CreateDate gt datetime'2014-04-29T12:12:49.5952511Z' and ProcessName eq 'xxxxxxxxxxx') and ((PartitionKey eq '2014042912' or PartitionKey eq '2014042913') or PartitionKey eq '2014042911'

Naturally this resulted in a bad request. While running the query manually with the closing bracket after [ProcessName eq 'xxxxxxxxxxx'] moved to the end of the query resulted in a 200.

Rewriting the query to

var existing = (from item in _table
              where (item.CreateDay == currentPartition || item.CreateDay == nextPartition || item.CreateDay == prevPartition)
             select item).ToList();

existing = existing.Where(f => f.CreateDate > mindate && f.ProcessName == processName).ToList();

did the job, but retrieves a bigger set from the server than needed.

dtretyakov commented 10 years ago

Thank you for posting, it'll be fixed in the next version.