通过C#访问的表存储中的实体的属性值为零

时间:2017-11-08 02:13:44

标签: c# azure-table-storage

我有一个存储deviceid,timestamp和pm1的表存储。我尝试使用C#访问具有特定设备ID且在特定时间范围内的实体。我能够得到我想要的实体,但这些实体的pm1读数是零,这是不正确的。表存储中不会丢失pm1读数。我怎么能解决这个问题?

这是我的代码:

main():
    string partitionFilter = TableQuery.GenerateFilterCondition("deviceid", QueryComparisons.Equal, StartEntity.deviceid);
            string date1 = TableQuery.GenerateFilterConditionForDate("ts", QueryComparisons.GreaterThanOrEqual,starttime);
            string date2 = TableQuery.GenerateFilterConditionForDate("ts", QueryComparisons.LessThanOrEqual, endtime);
            string datefilter = TableQuery.CombineFilters(date1, TableOperators.And, date2);
            string pm1con = TableQuery.GenerateFilterConditionForInt("pm1con", QueryComparisons.GreaterThan, 0);
            string finalFilter = TableQuery.CombineFilters(partitionFilter,TableOperators.And, datefilter);
            string extrafilter = TableQuery.CombineFilters(finalFilter, TableOperators.And, pm1con);
            TableQuery<EventEntity> RangeQueryforEnentEntities = new TableQuery<EventEntity>().Where(extrafilter);
            TableContinuationToken token = null;

            do
            {
                TableQuerySegment<EventEntity> resultSegment = EventsTable.ExecuteQuerySegmented(RangeQueryforEnentEntities, token);
                token = resultSegment.ContinuationToken;

                foreach (EventEntity entity in resultSegment.Results)
                {
                    EventEntities.Add(entity);
                    log.Info($"C# All the entities in current event: {entity.deviceid}, {entity.ts}, {entity.PM1Con}");
                }

            } while (token != null);

            return EventEntities; 

public class EventEntity : TableEntity
{
    public EventEntity(string deviceid, DateTime ts, int PM1Con, float TumblingB_threshold, float TumblingB_confidence)
    {
        this.PartitionKey = deviceid;
        this.RowKey = ts.ToLongDateString();
    }

    public EventEntity() { }

    public string deviceid { get; set; }

    public DateTime ts { get; set; }

    public float pm1con { get; set; }

    public float TumblingB_threshold { get; set; }

    public float TumblingB_confidence { get; set; }

}

这是返回的结果:

[2017-11-08 5:25:59 PM] C# All the entities in current event: HAVEN-0D0E0A-TZ-000115, 2017-10-25 2:42:00 AM, 0
[2017-11-08 5:25:59 PM] C# All the entities in current event: HAVEN-0D0E0A-TZ-000115, 2017-10-25 2:45:00 AM, 0
[2017-11-08 5:25:59 PM] C# All the entities in current event: HAVEN-0D0E0A-TZ-000115, 2017-10-25 2:51:00 AM, 0
[2017-11-08 5:25:59 PM] C# All the entities in current event: HAVEN-0D0E0A-TZ-000115, 2017-10-25 2:54:00 AM, 0
[2017-11-08 5:25:59 PM] C# All the entities in current event: HAVEN-0D0E0A-TZ-000115, 2017-10-25 2:57:00 AM, 0
[2017-11-08 5:25:59 PM] C# All the entities in current event: HAVEN-0D0E0A-TZ-000115, 2017-10-25 3:00:00 AM, 0
[2017-11-08 5:25:59 PM] C# All the entities in current event: HAVEN-0D0E0A-TZ-000115, 2017-10-25 3:03:00 AM, 0
[2017-11-08 5:25:59 PM] C# All the entities in current event: HAVEN-0D0E0A-TZ-000115, 2017-10-25 3:06:00 AM, 0
[2017-11-08 5:25:59 PM] C# All the entities in current event: HAVEN-0D0E0A-TZ-000115, 2017-10-25 3:09:00 AM, 0
[2017-11-08 5:25:59 PM] C# All the entities in current event: HAVEN-0D0E0A-TZ-000115, 2017-10-25 3:12:00 AM, 0
[2017-11-08 5:25:59 PM] C# All the entities in current event: HAVEN-0D0E0A-TZ-000115, 2017-10-25 3:15:00 AM, 0
[2017-11-08 5:25:59 PM] C# All the entities in current event: HAVEN-0D0E0A-TZ-000115, 2017-10-25 3:18:00 AM, 0

这是我想要的结果: enter image description here

因此您可以看到返回的pm1con值是错误的。

2 个答案:

答案 0 :(得分:0)

而不是entity.PM1Con使用entity.pm1con。

表实体转换是区分大小写的。

答案 1 :(得分:0)

问题在于数据类型。我使用float作为pm1con数据类型,但我应该使用double。