目前我有一个物联网设备模拟器,它向物联网中心发送消息,使用以下c#代码
for (int i = 0; i < 50; i++)
{
int cnt = new Random().Next(1, 5);
int Id = new Random().Next(1, 10);
var telemetryDataPoint = new
{
Time = DateTime.Now,
DeviceId = "myFirstDevice",
Counter = cnt,
RestId = Id,
};
var messageString = JsonConvert.SerializeObject(telemetryDataPoint);
var message = new Message(Encoding.ASCII.GetBytes(messageString));
await deviceClient.SendEventAsync(message);
Console.WriteLine("{0} > Sending message: {1}", DateTime.Now, messageString);
}
现在我有另一个c#控制台应用程序,它试图从azure表存储中读取数据
public class SimulatorDeviceEntity : TableEntity
{
public SimulatorDeviceEntity(string devId, string time )
{
this.PartitionKey = devId;
this.RowKey = time;
}
public SimulatorDeviceEntity() { }
public string counter { get; set; }
public string restid { get; set; }
public string deviceid { get; set; }
}
static void Main(string[] args)
{
StorageCredentials creds = new StorageCredentials(accountName, accountKey);
CloudStorageAccount account = new CloudStorageAccount(creds, useHttps: true);
CloudTableClient client = account.CreateCloudTableClient();
TableQuery<SimulatorDeviceEntity> query = new TableQuery<SimulatorDeviceEntity>().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "myFirstDevice"));
foreach (SimulatorDeviceEntity entity in table.ExecuteQuery(query))
{
Console.WriteLine("{0}, {1}t{2}t{3}", entity.PartitionKey, entity.RowKey,
entity.counter, entity.restid);
}
}
现在我在这里面临的问题是我得到的是我从表中得到所有的记录,但有1)列计数器的空表项,restId2) PartitionKey和RowKey
的正确值如何获取counter和restid的正确值
Azure Storage Table: SimulatorDevice2这是截图此处输入图像描述
尝试将计数器和restid 的类型从string更改为Int64。
public class SimulatorDeviceEntity : TableEntity
{
public SimulatorDeviceEntity(string devId, string time)
{
this.PartitionKey = devId;
this.RowKey = time;
}
public SimulatorDeviceEntity() { }
public Int64 counter { get; set; }
public Int64 restid { get; set; }
public string deviceId { get; set; }
}
同样,如果你想映射"time"属性,它是DateTime类型