Multiple filter conditions Azure table storage

后端 未结 5 759
半阙折子戏
半阙折子戏 2021-02-02 06:43

How can I set multiple filters on a Azure Table Storage?

This is what I\'ve tried:

string partitionFilter = TableQuery.GenerateFilterCondition(\"Partitio         


        
5条回答
  •  清歌不尽
    2021-02-02 07:15

    I am using Windows Azure Storage 7.0.0 and you can use Linq query so that you don't need to combine filters anymore:

    // filter dates for test
    var startDate = DateTime.Parse("01/02/2016 12:00:00 AM"); 
    var endDate = DateTime.Parse("02/02/2016 12:00:00 AM");
    
    // Get the cloud table
    var cloudTable = GetCloudTable();
    
    // Create a query: in this example I use the DynamicTableEntity class
    var query = cloudTable.CreateQuery()
            .Where(d => d.PartitionKey == "partition1"
                   && d.Timestamp >= startDate && d.Timestamp <= endDate);
    
    // Execute the query
    var result = query.ToList();
    

    Here is the generated query :

    ((PartitionKey eq 'partition1') and (Timestamp ge datetime'2016-01-31T11:00:00Z')) and (Timestamp le datetime'2016-02-01T11:00:00Z')

    You can notice that:

    • The filters have been combined.
    • The dates have been converted to UTC.

提交回复
热议问题