您可以覆盖 TableEntity 中的 WriteEntity 方法并删除任何具有您的自定义属性的属性。
public class CustomTableEntity : TableEntity
{
public override IDictionary<string, EntityProperty> WriteEntity(Microsoft.WindowsAzure.Storage.OperationContext operationContext)
{
var entityProperties = base.WriteEntity(operationContext);
var objectProperties = GetType().GetProperties();
foreach (var property in from property in objectProperties
let nonSerializedAttributes = property.GetCustomAttributes(typeof(NonSerializedOnAzureAttribute), false)
where nonSerializedAttributes.Length > 0
select property)
{
entityProperties.Remove(property.Name);
}
return entityProperties;
}
}
[AttributeUsage(AttributeTargets.Property)]
public class NonSerializedOnAzureAttribute : Attribute
{
}
用法
public class MyEntity : CustomTableEntity
{
public string MyProperty { get; set; }
[NonSerializedOnAzure]
public string MyIgnoredProperty { get; set; }
}