码迷,mamicode.com
首页 > 其他好文 > 详细

存入azure table是忽略某个属性

时间:2014-10-17 15:10:08      阅读:100      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   os   ar   for   sp   div   

 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; }
    }

 There is an attribute called WindowsAzure.Table.Attributes.IgnoreAttribute can be set on the property you want to exclude.

 

存入azure table是忽略某个属性

标签:style   blog   color   io   os   ar   for   sp   div   

原文地址:http://www.cnblogs.com/akingyao/p/4031047.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!