【问题标题】:Azure Storage Table query by DateTime not returning any results按日期时间查询 Azure 存储表未返回任何结果
【发布时间】:2013-07-16 05:35:14
【问题描述】:

我正在尝试根据“时间”字段(DateTime 对象)在 Azure 存储表中显示条目。但是,当我尝试基于DateTime 进行查询时,我没有任何运气。

我尝试了不同的条件,例如:

  1. 时间 = g.Time
  2. time.Equals(g.Time)
  3. time.Ticks == g.Time.Ticks
  4. time.ToString() == g.Time.ToString()
  5. time.ToString().Equals(g.Time.ToString())

        DateTime time = Convert.ToDateTime(timePoint);
        TableServiceContext tableServiceContext = tableClient.GetDataServiceContext();
        var query = from g in tableServiceContext.CreateQuery<MyEntry>(tableName)
                       where time.Ticks == g.Time.Ticks
                    select g;
    

我已成功显示基于不同 string 字段的条目,但现在我想使用 DateTime,它无法正常工作。

您是否必须以不同方式处理 DateTime 对象?有什么好办法吗?

谢谢!

编辑:当我创建要放入表中的条目时,我验证时间至少等于一个条目。

【问题讨论】:

    标签: c# azure azure-storage azure-table-storage


    【解决方案1】:

    我通过使用以下条件将时间设置为我的分区键来让它工作:

    where g.PartitionKey.Equals(time.ToString("yyyyMMddHHmm"))
    

    但是,我仍然不清楚为什么这有效,而其他搜索方法不起作用。

    【讨论】:

    • 我认为 rowkey 和 partition key 是简单的字符串值,只有字符串比较可能有效。其他比较只用 ToString() 来比较。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-19
    • 2021-03-20
    • 1970-01-01
    相关资源
    最近更新 更多