简体   繁体   中英

Design Query on Azure Table Storage

I have 2 C# MVC models

  1. SignalModel
  2. DeviceSignalModel

SignalModel ==> contains the properties of Signal say MasterSignal

DeviceSignalModel ==> contains all signal properties pertaining to a Device

So both are expected to have same properties except that DeviceSignalModel need to have an additional property of DeviceID.

The Model SignalModel will have columns ==> id,name,unit,range ... representing the Azure Storage Table signal .

I use below to get the data from table signal

TableOperation retOp = TableOperation.Retrieve<SignalModel>(..,..,..);
TableResult tr = table.Execute(retOp);

I have another Azure Storage Table devicesignal and its represented by a model DeviceSignalModel I have designed the Model as

public class DeviceSignalModel : TableEntity, IAzureTableStorage
    {
        //public int DeviceSignalKey { get; set; }// RowKey for Unique Key
        //public string DeviceSignalID { get; set; }// PartitionKey of Storage Table Device

        public SignalModel Signal { get; set; }//<===== (A) Model here right?

And to get data from devicesignal I use the below

TableOperation retOp = TableOperation.Retrieve<DeviceSignalModel>(..,..,..);
TableResult tr = table.Execute(retOp);

With the above query I don't get values of columns represented within SignalModel from devicesignal table(statement (A) above). I get a null for property Signal.

My Query

1.Is the statement (A) in above snippet not possible?

  1. Should all the properties in SignalModel be explicitly placed inside the DeviceSignalModel (instead of having an object Signal as property?
  2. If so what is the best option to avoid adding same properties in both Signal and DeviceSignal when there is a future change (add property) to Signal Table.

You can not make your custom SignalModel as Property type. If you want to maintain SignalModel type object information in a DeviceSignalModel entity, you can try to serialize the SignalModel type object into JSON string and save it as property value of DeviceSignalModel entity. Or as davethecoder said, if possible, you can use Azure DocumentDB to store your data.

Besides, to implement relationships between Signal and DeviceSignal in Azure Table service, as you mentioned, placing particular properties of SignalModel entity inside the DeviceSignalModel entity could be a approach. In addition, you can refer to this article to know about modelling relationships and table design patterns in Azure Table service.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM