コード例 #1
0
        // This manually parses the XML that comes back.
        // This function uses code from this blog entry:
        // http://blogs.msdn.com/b/avkashchauhan/archive/2011/03/28/reading-and-saving-table-storage-entities-without-knowing-the-schema-or-updating-tablestorageentity-schema-at-runtime.aspx
        public static void OnReadingEntity(object sender, Client.ReadingWritingEntityEventArgs args)
        {
            GenericEntity entity = args.Entity as GenericEntity;

            if (entity == null)
            {
                return;
            }

            // read each property, type and value in the payload
            var properties = args.Entity.GetType().GetProperties();
            var q          = from p in args.Data.Element(AtomNamespace + "content")
                             .Element(MetadataNamespace + "properties")
                             .Elements()
                             where properties.All(pp => pp.Name != p.Name.LocalName)
                             select new
            {
                Name     = p.Name.LocalName,
                IsNull   = string.Equals("true", p.Attribute(MetadataNamespace + "null") == null ? null : p.Attribute(MetadataNamespace + "null").Value, StringComparison.OrdinalIgnoreCase),
                TypeName = p.Attribute(MetadataNamespace + "type") == null ? null : p.Attribute(MetadataNamespace + "type").Value,
                p.Value
            };

            foreach (var dp in q)
            {
                string value = dp.Value;
                if (!string.IsNullOrWhiteSpace(value))
                {
                    value = string.Empty;
                }
                entity.properties[dp.Name] = dp.Value;
            }
        }
コード例 #2
0
        private void InitColumnNames()
        {
            if (_columnNames == null)
            {
                TableServiceContext ctx = _tableClient.GetDataServiceContext();
                ctx.IgnoreMissingProperties = true;
                ctx.ReadingEntity          += GenericTableReader.OnReadingEntity;

                var           x   = from o in ctx.CreateQuery <GenericEntity>(_tableName) select o;
                GenericEntity all = x.First();

                List <string> props = new List <string>();
                props.Add("PartitionKey");
                props.Add("RowKey");

                props.AddRange(all.properties.Keys);

                _columnNames = props.ToArray();
            }
        }