2016-10-06 5 views
0
을 돌려

현재 내가푸른 저장 쿼리 널 열

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# 콘솔 응용 프로그램을 C# 코드 다음 아 파크 IOT HUB에 메시지를 보내는 IOT 장치 시뮬레이터를 가지고있다

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); 
     } 
     } 

같은 푸른 테이블 저장 지금 내가 여기에 직면하고있는 열 couter에 나는 테이블에서하지만 1) null 항목과 모든 레코드를 얻고있다 얻을 수있다 실행,을 restId2) 올바른에 PartitionKey의 값과 RowKey

카운터에 대한 정확한 값을 얻을

푸른 저장 표를 restid 방법 : SimulatorDevice2 여기 enter image description here

+0

테이블 저장소에 메시지를 추가하는 코드를 공유 할 수도 있습니까? 그러면 무슨 일이 일어나는지 알 수 있습니다. –

+0

시뮬레이터가 IOT 허브에 메시지를 보내면 데이터를 Azure 테이블에 넣습니다. 쿼리는 다음과 같습니다. SELECT DeviceId, RestId, Time, Counter INTO v2deviceOutputfrom v2deviceInput 여기서 DeviceId는 null이 아닙니다. 참고 : v2deviceInput 및 v2deviceOutput은 Stream Analytics로 구성된 입력 출력입니다. –

+0

@VaibhavRamteke, 아직 행운이 있습니까? – Jackie

답변

0

카운터의 유형을 변경해보십시오 스크린 샷입니다 을 문자열에서 Int64으로 restid합니다.

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; } 
} 

마찬가지로 "시간"속성을 매핑하려는 경우 DateTime 유형입니다.