我有一个Record
具有 aName
和 a的对象Theme
。
Theme 是嵌入在类型化类中的 KeyValue 对,例如“01”-“Sport”、“02”-“Home”等
我有一个这样的对象:
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; }
}
问题是当我尝试从 Azure 表中加载该记录时,如下所示:
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;
}
我获得了record.Name
,但record.Theme
仍然始终为“null”,不会从“记录”表中加载,就像:
Partition Key Name Theme
"record" "x" "test" "01"
也在我的“主题”表中
Partition Key Description
"en" "01" "Sport"
我试图将构造函数添加到“主题”类
public class Theme : DescriptionEntity
{
public Theme() : base() { }
public Theme(string key) : base(key) { }
}
但这并没有改变结果......
有没有办法明确地说“取字符串“主题”并用于new Theme(string)
创建Theme
属性”