C# Azure表存储-为什么存储我的bool和string属性,而不存储我的int和double属性?
这听起来应该是一个简单的问题,但我很难把它挑出来 我有一个C# Azure表存储-为什么存储我的bool和string属性,而不存储我的int和double属性?,c#,azure,C#,Azure,这听起来应该是一个简单的问题,但我很难把它挑出来 我有一个TableEntity类,我正试图将其写入Azure表存储: public class MyEntity : TableEntity { public MyEntity(string imageId, string featureId) { this.PartitionKey = imageId; this.RowKey = featureId; } public string Container { g
TableEntity
类,我正试图将其写入Azure表存储
:
public class MyEntity : TableEntity
{
public MyEntity(string imageId, string featureId)
{
this.PartitionKey = imageId;
this.RowKey = featureId;
}
public string Container { get; set; }
public bool FeatureEnabled { get; set; }
public int data;
public PointF Point;
public double X;
public double Y;
}
我知道我的点
属性不会保存到表存储中。但是当我插入这个实体时,Container
属性和FeatureEnabled
都会被存储,而其他什么都不会被存储
这怎么可能
int
和double
被认为是受支持的,那么我在这里会做错什么呢?容器和功能启用
是类的属性。其他的只是字段<代码>表格实体将仅搜索并自动保存(受支持类型的)属性
因此,通过提供
get,将数据、x和y转换为属性;设置编码>的方式与工作的方式相同。您需要为int/double属性定义getter/setter:
public class MyEntity : TableEntity
{
public MyEntity(string imageId, string featureId)
{
this.PartitionKey = imageId;
this.RowKey = featureId;
}
public string Container { get; set; }
public bool FeatureEnabled { get; set; }
public int data { get; set; }
public PointF Point;
public double X { get; set; }
public double Y { get; set; }
}
TableEntity支持的属性类型非常有限
如果您使用我实现的ObjectFlatterRecomposer API
您可以获取所有属性,包括写入表存储的Point属性,当您从表存储中读回实体时,api还将处理原始对象的重新组合
下面是一个使用示例:
using ObjectFlattenerRecomposer;
//Flatten object and convert it to EntityProperty Dictionary
Dictionary<string, EntityProperty> flattenedProperties = EntityPropertyConverter.Flatten(complexObject);
// Create a DynamicTableEntity and set its PK and RK
DynamicTableEntity dynamicTableEntity = new DynamicTableEntity(partitionKey, rowKey);
dynamicTableEntity.Properties = flattenedProperties;
// Write the DynamicTableEntity to Azure Table Storage using client SDK
//Read the entity back from AzureTableStorage as DynamicTableEntity using the same PK and RK
DynamicTableEntity entity = [Read from Azure using the PK and RK];
//Convert the DynamicTableEntity back to original complex object.
Imagine original complexObject was of type Order.
Order order = EntityPropertyConverter.ConvertBack<Order>(entity.Properties);
使用ObjectFlatterRecomposer;
//展平对象并将其转换为EntityProperty字典
Dictionary FlattedProperties=EntityPropertyConverter.Flatte(complexObject);
//创建DynamicTableEntity并设置其PK和RK
DynamicTableEntity DynamicTableEntity=新的DynamicTableEntity(partitionKey,rowKey);
dynamicTableEntity.Properties=扁平化属性;
//使用客户端SDK将DynamicTableEntity写入Azure表存储
//使用相同的PK和RK将实体作为DynamicTableEntity从AzureTableStorage读回
DynamicTableEntity=[使用PK和RK从Azure读取];
//将DynamicTableEntity转换回原始复杂对象。
设想原始complexObject是Order类型。
Order Order=EntityPropertyConverter.ConvertBack(entity.Properties);
啊!这很有道理!谢谢只要你允许,我会尽快接受。