【发布时间】:2018-06-18 11:49:48
【问题描述】:
我正在尝试从我们办公室的表格存储中提取一些数据。除了时间戳之外,我可以让所有类型的查询都能正常工作。他们不断给我一个 HTTP 错误 400 错误请求。检查它时,确切的错误文本是
"'Timestamp eq 中位置 20 的语法错误 2018-06-04T12:05:31.9150000Z'。 请求ID:3949e07b-b002-003f-59f8-065461000000 时间:2018-06-18T11:38:28.7307368Z".
我访问特定数据的代码是;
var lowerlimit = DateTime.Now.AddDays(-20);
TableQuery<LogEntity> query = new TableQuery<LogEntity>().Where(TableQuery.GenerateFilterConditionForDate("Timestamp", QueryComparisons.GreaterThan, lowerlimit));
作为示例,此代码有效;
TableQuery<LogEntity> query = new TableQuery<LogEntity>().Where(TableQuery.GenerateFilterCondition("Level", QueryComparisons.Equal, "Warn"));
我找不到和我有同样问题的人,所以我希望你能帮助我!提前致谢!
*edit* here is the full code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Azure; // Namespace for CloudConfigurationManager
using Microsoft.Azure.Storage; // Namespace for StorageAccounts
using Microsoft.Azure.CosmosDB.Table; // Namespace for Table storage types
using Newtonsoft.Json;
namespace DataPullingViregoLog
{
class Program
{
static void Main(string[] args)
{
var lowerlimit = DateTimeOffset.Now.AddDays(-20);
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
CloudConfigurationManager.GetSetting("StorageConnectionString"));
CloudTableClient tableClient =
storageAccount.CreateCloudTableClient();
// Create the CloudTable object that represents the "people" table.
CloudTable table = tableClient.GetTableReference("{dbname}");
TableQuery<LogEntity> query = new TableQuery<LogEntity>
().Where(TableQuery.GenerateFilterConditionForDate("Timestamp",
QueryComparisons.GreaterThan, lowerlimit));
IEnumerable<LogEntity> table2 = table.ExecuteQuery(query);
var listOfEntities = new List<LogEntity>();
foreach (LogEntity entity in table2)
{
listOfEntities.Add(entity);
Console.WriteLine("{0}, {1}\t{2}\t{3}", entity.PartitionKey,
entity.RowKey,
entity.Level, entity.MessageWithLayout);
}
var convertedJson = JsonConvert.SerializeObject(listOfEntities,
Formatting.Indented);
}
}
internal class LogEntity : TableEntity
{
public LogEntity(string PartitionKey, string Rowkey, DateTime Timestamp)
{
this.PartitionKey = PartitionKey;
this.RowKey = RowKey;
this.Timestamp = Timestamp;
}
public LogEntity() { }
public string LogTimeStamp { get; set; }
public string Level {get;set;}
public string LoggerName { get; set; }
public string Message { get; set; }
public string MessageWithLayout { get; set; }
public string MachineName { get; set; }
public long LogTimeTicks { get; set; }
public string Exception { get; set; }
}
/拉斯穆斯
【问题讨论】:
-
它是自定义列还是标准时间戳列?因为那个是
DateTimeOffset,你试过把你的lowerlimit改成那个吗? This answer uses DateTimeOffset -
它抛出了同样的异常和同样的错误代码。我不知道它是否是标准,但是当比较字符串 1 到 1 时,它们看起来完全一样。
-
我无法重现您在我身边提到的问题。我使用带有 Azure 存储帐户的最新 WindowsAzure.Storage 9.20 版本对其进行了测试。如果可能,请使用最新的 Azure 存储并重试。
-
这很奇怪,因为根据我的理解,查询字符串应该是:Timestamp eq datetime'2018-06-04T12:05:31.9150000Z'
-
我发送的日期是 2018-06-04T12:05:31.9150000Z 而数据库中的日期看起来像 2018-06-04T12:07:01.371Z 。如您所见,唯一的区别在于尾随零。这可能是问题吗?据我所知,问题是我的代码发出的请求。显然在 20 号空间有错误。@ZhaoxingLu-Microsoft 你是说 ' ' 应该在日期附近吗?
标签: c# .net azure azure-table-storage