2012-05-25 177 views
0

删除列下面是一个代码片段,我用读表存储实体:从Azure的表存储

public void OnReadingEntity(object sender, ReadingWritingEntityEventArgs args) 
    { 
     XNamespace AtomNamespace = "http://www.w3.org/2005/Atom"; 
     XNamespace AstoriaMetadataNamespace = "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"; 

     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(AstoriaMetadataNamespace + "properties") 
           .Elements() 
       where properties.All(pp => pp.Name != p.Name.LocalName) 
       select new 
       { 
        Name = UnescapePropertyName(p.Name.LocalName), 
        IsNull = string.Equals("true", p.Attribute(AstoriaMetadataNamespace + "null") == null 
         ? null 
         : p.Attribute(AstoriaMetadataNamespace + "null").Value, StringComparison.OrdinalIgnoreCase), 
        TypeName = p.Attribute(AstoriaMetadataNamespace + "type") == null 
         ? null 
         : p.Attribute(AstoriaMetadataNamespace + "type").Value, 
        p.Value 
       }; 

     foreach (var dp in q) 
     { 
      entity[dp.Name] = GetTypedEdmValue(dp.TypeName, dp.Value, dp.IsNull); 
     } 
    } 

不幸的是这一段代码将返回,在我已经删除的实体存在的一些特性。

有人可以解释这是为什么吗?

回答

1

Azure表存储不像您以前在关系数据库中那样有列。除了强制性列以外,每行可以具有完全不同的属性。

当你说“仍显示”我猜想这只是您所使用的工具是展示是让你觉得它就像一个关系表中的数据的方式。

查看http://msdn.microsoft.com/en-us/magazine/ff796231.aspx有一些很好的技术背景。

+0

嗨托德,你是完全正确的,我写的帖子在赶时间,所以它更有意义做了编辑。 – Calin

+1

啊,这更有意义。您正在使用存储模拟器还是现场服务?如果它的模拟器,你可能会看到这里http://stackoverflow.com/questions/3076499/windows-azure-table-services-extended-properties-and-table-schema描述 –

+0

感谢,这是问题的问题 – Calin