Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
148 views
in Technique[技术] by (71.8m points)

c# - Timestamp query in Azure

I am really stuck in my query filter on Azure table storage. May I know how to query with timestamp please? When I query for partition key to 1005 alone, I am getting the complete table which I don't want. When I added "and" condition with timestamp (tried with lots of formats but it is not returning anything. Code snippet below :

var lowerlimit = DateTime.Today.AddDays(-52).ToString("yyyy-MM-dd");

string dateRangeFilter = TableQuery.CombineFilters(
    TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "1005"),
    TableOperators.And,
    TableQuery.GenerateFilterCondition("TimeStamp", QueryComparisons.GreaterThanOrEqual, lowerlimit));
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I am able to use the Timestamp with Microsoft.WindowsAzure.Storage version 4.0.1.0. Just and example

var query = TableQuery.CombineFilters(
            TableQuery.GenerateFilterCondition("Level", QueryComparisons.Equal, "ERROR"), 
            TableOperators.And, 
            TableQuery.GenerateFilterConditionForDate("Timestamp", QueryComparisons.GreaterThanOrEqual, DateTimeOffset.Now.AddDays(-20).Date));

var query2 = TableQuery.CombineFilters(query,
            TableOperators.And, 
            TableQuery.GenerateFilterConditionForDate("Timestamp", QueryComparisons.LessThanOrEqual, DateTimeOffset.Now));

var exQuery = new TableQuery<LogEntry>().Where(query2);

CloudTableClient tableClient = _storageAccount.CreateCloudTableClient();

CloudTable table = tableClient.GetTableReference(_tableName);
var results = table.ExecuteQuery(exQuery).Select(ent => (T) ent).ToList();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...