Reputation: 21
I am building project to store sensors data from IoT devices. I use IoT Hub, Stream Analytics and Table Storage.
I have Web API which I want to return values from Table in Table Storage. I don't know why I getting null values in response from Table Storage only in custom columns. I know that columns in Table Storage are case-sensitive and I remembered about it.
What is really interesting when I add Row to Table from .NET SDK and next query it also with SDK, I'm getting correct values (not null :) )
This is how data looks like in Storage Explorer in Azure Portal:
This shows that columns have correct case-sensitive names:
Here is TableValue Entity from my code:
public class TableValue : TableEntity
{
public TableValue() { }
public TableValue(string id, string deviceId)
{
PartitionKey = deviceId;
RowKey = id;
}
public string Humidity { get; set; }
public string Pressure { get; set; }
public string Temperature { get; set; }
public string SentTimestamp { get; set; }
}
Here is my code responsible for querying values from table storage
public async Task<List<TableValue>> Handle(Query request, CancellationToken cancellationToken)
{
var table = _tableClient.GetTableReference("iotinsights");
var condition = TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "Develop1");
var query = new TabyleQuery<TableValue>().Where(condition);
var result = table.ExecuteQuery(query);
return await Task.FromResult(result.ToList());
}
Here is result I got from request in Postman:
{
"humidity": null,
"pressure": null,
"temperature": null,
"sentTimestamp": null,
"partitionKey": "Develop1",
"rowKey": "0131560c-d1d7-4dc3-93f0-14a4c676baa5",
"timestamp": "2020-12-28T12:21:55.9198819+01:00",
"eTag": "W/\"datetime'2020-12-28T11%3A21%3A55.9198819Z'\""
},
{
"humidity": null,
"pressure": null,
"temperature": null,
"sentTimestamp": null,
"partitionKey": "Develop1",
"rowKey": "022bc3f8-c8d5-4ff5-88b6-57e53c720aa9",
"timestamp": "2020-12-28T12:27:22.9991905+01:00",
"eTag": "W/\"datetime'2020-12-28T11%3A27%3A22.9991905Z'\""
}, ...
What should I do to get correct values from this Table?
Upvotes: 1
Views: 791
Reputation: 21
I found solution, it was easier than i thought. Custom Table Entity properties must have correct data types
public class TableValue : TableEntity
{
public TableValue() { }
public TableValue(string id, string deviceId)
{
PartitionKey = deviceId;
RowKey = id;
}
public Double? Humidity { get; set; }
public Double? Pressure { get; set; }
public Double? Temperature { get; set; }
public DateTime? SentTimestamp { get; set; }
}
Upvotes: 1