I have an object Record
that has a Name
and a Theme
.
A Theme is a KeyValue pair embedded in a typed class, like "01"-"Sport", "02"-"Home" etc
I have an object like this:
public class DescriptionEntity : TableEntity
{
public string Description { get; set; }
public string Key { get { return RowKey; } set { RowKey = value; } }
public DescriptionEntity() { }
}
public class Theme : DescriptionEntity
{
}
/* The Record has a "string" and a "Theme" property */
public class Record : TableEntity
{
[...]
public string Name { get; set; }
public Theme Theme { get; set; }
}
The problem is when I try to load that record from the Azure Tables, like this:
var record = await repository.GetTableEntityAsync<Record>(id, RecordConst.RecordPartitionKey);
// ..........................
public async Task<T> GetTableEntityAsync<T>(string rowKey, string partitionKey) where T : ITableEntity, new()
{
var table = GetTable<T>();
TableQuery<T> query = new TableQuery<T>().Where(
TableQuery.CombineFilters(
TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, partitionKey),
TableOperators.And,
TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.Equal, rowKey))).Take(1);
var result = new T();
TableContinuationToken continuationToken = null;
do
{
Task<TableQuerySegment<T>> querySegment = table.ExecuteQuerySegmentedAsync(query, continuationToken);
TableQuerySegment<T> segment = await querySegment;
result = segment.FirstOrDefault();
continuationToken = segment.ContinuationToken;
} while (continuationToken != null);
return result;
}
I obtain the record.Name
, but the record.Theme
remains always "null", does not load from the "Record" table, that is like:
Partition Key Name Theme
"record" "x" "test" "01"
also in my "Theme" table I have
Partition Key Description
"en" "01" "Sport"
I tried to add to the "Theme" class the constructors
public class Theme : DescriptionEntity
{
public Theme() : base() { }
public Theme(string key) : base(key) { }
}
but this didn't change the result...
Is there a way to explicitly say "take the string "Theme" and use new Theme(string)
to create the Theme
property"