0
votes

I serached in web, but didn't find any solution.please help me in resolving this.

Question: i have a webapi with azure table storage, when i query azure table the webapi json response included with partitionkey and rowkey. i want my web api response excluded with partitionkey and rowkey of azure table.

Current output:{"partitionkey":"test","Rowkey":"abc","name":"user","email":"[email protected]","domain":"qwe"}

Expected output: {"name":"user","email":"[email protected]","domain":"qwe"}

3
Welcome to stackoverflow. Your question is not clear. Are you asking us to provide with the completed to do the job? If so, that's not what we do here. Have you already written some code and it's not working? If so, provide the code and the error message.curt

3 Answers

1
votes

when i query azure table, the webapi json response included with partitionkey and rowkey. i want my web api response excluded with partitionkey and rowkey of azure table.

You could try to use query projection to return a limited set of properties from the entities while selecting entities from Azure Table storage. The following query is for your reference.

TableQuery<EmployeeEntity> EmpQuery = table.CreateQuery<EmployeeEntity>();
var query = (from ep in EmpQuery
             where ep.PartitionKey == "pkvalue" && ep.RowKey== "rkvalue"
             select new { Fname = ep.FirstName, Lname = ep.LastName}).AsTableQuery();
var emps = query.Execute();
1
votes

You can use property SelectColumns in TableQuery class to specify the columns you want to query from Azure Storage Table Service.

1
votes

The key point to exclude PartitionKey and RowKey from result is to set ProjectSystemProperties of TableRequestOptions to false.

So the code above should be modified like this:

var emps = query.Execute(new TableRequestOptions { ProjectSystemProperties = false });

Another working example:

var query = new TableQuery<Event>()
    .Where(
        TableQuery.GenerateFilterCondition(
            "PartitionKey", QueryComparisons.Equal, partitionKey))
    .Select(new[] { "Id" });

var results = table.ExecuteQuery(query, 
    new TableRequestOptions { ProjectSystemProperties = false });

Then you will get response like this:

{"odata.etag":"W/\"datetime'2017-10-27T08%3A05%3A40.6551979Z'\"","Id":"Event-1" },
{"odata.etag":"W/\"datetime'2017-10-27T09%3A05%3A40.6551979Z'\"","Id":"Event-2" },
...

To avoid odata.etag in result, specify PayloadFormat in TableRequestOptions and get exactly what you want:

var results = table.ExecuteQuery(query, 
    new TableRequestOptions { 
        ProjectSystemProperties = false, 
        PayloadFormat = TablePayloadFormat.JsonNoMetadata 
});

Result:

{ "Id":"Event-1" },{ "Id":"Event-2" },...