Azure表存储:字符串''不是有效的AllXsd值

时间:2012-06-29 14:43:05

标签: c# azure azure-table-storage

当我尝试从Table Storage读取时,我收到以下异常。我在添加DateTime?属性后得到了它。

例外:

The current value 'String.Empty' type is not compatible with the expected 'System.DateTime' type.

内部异常:

The string '' is not a valid AllXsd value.

我想到了以下解决方案:

  1. 我让提供程序将不存在的值映射为null
  2. 使用日期更新对象(但我无法获取它?)
  3. 有没有人对如何解决这个问题有更好的了解?

    堆栈跟踪:

    System.InvalidOperationException: The current value 'String.Empty' type is not compatible with the expected 'System.DateTime' type. ---> System.FormatException: The string '' is not a valid AllXsd value.
       at System.Xml.Schema.XsdDateTime..ctor(String text, XsdDateTimeFlags kinds)
       at System.Xml.XmlConvert.ToDateTime(String s, XmlDateTimeSerializationMode dateTimeOption)
       at System.Data.Services.Client.ClientConvert.ChangeType(String propertyValue, Type propertyType)
       --- End of inner exception stack trace ---
       at System.Data.Services.Client.ClientConvert.ChangeType(String propertyValue, Type propertyType)
       at System.Data.Services.Client.AtomMaterializer.MaterializeDataValue(Type type, AtomContentProperty atomProperty, DataServiceContext context)
       at System.Data.Services.Client.AtomMaterializer.MaterializeDataValues(ClientType actualType, List`1 values, Boolean ignoreMissingProperties, DataServiceContext context)
       at System.Data.Services.Client.AtomMaterializer.MaterializeResolvedEntry(AtomEntry entry, Boolean includeLinks)
       at System.Data.Services.Client.AtomMaterializer.Materialize(AtomEntry entry, Type expectedEntryType, Boolean includeLinks)
       at System.Data.Services.Client.AtomMaterializer.DirectMaterializePlan(AtomMaterializer materializer, AtomEntry entry, Type expectedEntryType)
       at System.Data.Services.Client.AtomMaterializerInvoker.DirectMaterializePlan(Object materializer, Object entry, Type expectedEntryType)
       at System.Data.Services.Client.ProjectionPlan.Run(AtomMaterializer materializer, AtomEntry entry, Type expectedType)
       at System.Data.Services.Client.AtomMaterializer.Read()
       at System.Data.Services.Client.MaterializeAtom.MoveNextInternal()
       at System.Data.Services.Client.MaterializeAtom.MoveNext()
       at System.Linq.Enumerable.<CastIterator>d__b1`1.MoveNext()
       at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
       at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
    

    模型

    class Car : TableServiceEntity {
    
     public DateTime? LastUpdated { get; set; }
     public DateTime? LastUsed { get; set; }
    
    // more properties
    
    }
    

    查询

     var sx = this.GetServiceContext();
     return (from x in sx.CreateQuery<Car>("Table") select x).ToList();
    

1 个答案:

答案 0 :(得分:0)

如果有人用Google搜索,我找到了解决方案:

我正在使用Azure存储资源管理器,当我在测试时更新了另一个属性时,它在其中一个实体中保存了一个空字符串而不是可以为空的日期。