Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DynamicTableEntity PartitionKey and RowKey

I create DynamicTableEntity as follows:

string env = "envTest";
stting ver = "1.0";
siring id = "12356";
string mode = "verify";
DynamicTableEntity entryEntity = DynamicTableEntity(env,ver);
entryEntity.Properties.Add("Id", id);
entryEntity.Properties.Add("Mode", mode);

As a result created a table with columns:"Id", "Mode", "PartitionKey", "RowKey" I want to change the names of "PartitionKey", "RowKey", i.e. I want the env to be a partitionKey but but The column name to be "Env". How can I do it?

like image 391
Yakov Avatar asked Nov 24 '14 14:11

Yakov


2 Answers

Although it's true that you can't rename PartitionKey and RowKey, you can resolve to a DTO straight from the table.

I find this super handy for projecting the data to different audiences (i.e limited view for non-admins etc)

HTH

var query = MyEntityDBO.CreateQuery<DynamicTableEntity>()
            .Where(x => x.PartitionKey.Equals("Blah"))
            .Resolve(MyEntityDTO.GetEntityResolver());
var segment = await query.ExecuteSegmentedAsync(new TableContinuationToken());
if(segment.Results.Count > 0) {
     // Results = IEnumerable<MyEntityDTO>
}

public class MyEntityDTO
{
    public string Id { get; set; }
    public string Mode { get; set;  }
    public string Env { get; set; }
    public string Ver { get; set; }

    public static EntityResolver<MyEntityDTO> GetEntityResolver()
    {
        return (pk, rk, ts, props, etag) =>
        { 
             Env = pk,
             Ver = rk,
             Id = props["Id"].StringValue,
             Mode = props["Mode"].StringValue
        };
    }
}
like image 56
Peter Lea Avatar answered Oct 17 '22 16:10

Peter Lea


Simple answer is that you can't. PartitionKey and RowKey are system defined attributes (along with Timestamp) and you can't change their name. What you could do is define two more custom attributes for Env and Ver if you need to access the properties by these names in your application.

DynamicTableEntity entryEntity = DynamicTableEntity(env,ver);
entryEntity.Properties.Add("Id", id);
entryEntity.Properties.Add("Mode", mode);
entryEntity.Properties.Add("Env", env);
entryEntity.Properties.Add("Ver", ver);
like image 33
Gaurav Mantri Avatar answered Oct 17 '22 17:10

Gaurav Mantri